Line continuation and comments

avi.e.gross at gmail.com avi.e.gross at gmail.com
Thu Feb 23 21:20:52 EST 2023


Many "warnings" can safely be ignored.

The function as shown does not look right. I assume it is just an example, but a function that ignores the argument supplied is already a tad suspect.

Since it is SUGGESTED that the variable name "self" normally is used in a method for a class/instance, it is of course possible for it to set a variable called LEGAL_AGE_US to 21 and for no special reason, returns the age.

But my imagination is that a function called is_adult() should perhaps receive an age either as an argument, or an attribute of the current object and return True only if that age is greater than or equal to the legal age. Of course LEGAL_AGE_US may suggest a family of such functions specifying a legal age threshold for various countries or regions and all you need is the age between non-adult and adult. 

So one GUESS I have is that if this is a method, then you are seen not as setting a constant inside the function, where all-caps might be sensible but as setting an instance variable or changing it. A true constant might have been set when the class was designed or perhaps in __init__() or similar. 

I wonder how PyCharm would react if you used:

self.LEGAL_AGE_US = 21



-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com at python.org> On Behalf Of dn via Python-list
Sent: Thursday, February 23, 2023 9:01 PM
To: python-list at python.org
Subject: Re: Line continuation and comments

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'.
>> 
> 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.


Today, I wasn't criticised for:
> 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'.

Perhaps that came from AWS CodeWhisperer which I have since abandoned, 
or maybe from SonarLint (which I've just checked to discover it is not 
working properly...)

-- 
Regards,
=dn

-- 
https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list