Line continuation and comments
Cameron Simpson
cs at cskk.id.au
Thu Feb 23 22:50:39 EST 2023
On 24/02/2023 12.45, Weatherby,Gerard wrote:
>>NB my PyCharm-settings grumble whenever I create an identifier which
>>is
>>only used once (and perhaps, soon after it was established). I
>>understand the (space) optimisation, but prefer to trade that for
>>'readability'.
It isn't "space". Got an example for that warning? I don't use PyCharm,
but the main linter warning I get is an _unused_ variable, eg:
def f():
x = 3
I set x and never use it. Likely brain fade on my part, and worth a
warning.
On 24Feb2023 15:01, dn <PythonList at DancesWithMice.info> wrote:
>>I haven’t seen that one. What I get is warnings about:
>>
>>def is_adult( self )->bool:
>> LEGAL_AGE_US = 21
>> return LEGAL_AGE
>>
>>It doesn’t like LEGAL_AGE_US being all caps if declared in a function.
>
>Yes, I suffered this one too.
>
>The rationale comes from PEP-008 (Constants):
>
>Constants are usually defined on a module level and written in all
>capital letters with underscores separating words.
Yeah. The above looks like a method. I'd probably have something like:
class C:
LEGAL_AGE_US = 21
def is_adult(self) -> bool:
return self.age >= self.LEGAL_AGE_US
Variables used (self). Constant a class attribute.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list