pylint, was Re: pygame - importing GL - very bad...

someone newsboost at
Thu Jan 3 03:24:25 CET 2013

On 01/03/2013 12:52 AM, Steven D'Aprano wrote:
> On Wed, 02 Jan 2013 09:26:32 -0500, Dave Angel wrote:

>> Global const values should be ALL_CAPS, so it's obvious that nobody
>> intends to modify them.
> Like math.pi I suppose? *wink*


>> It's the non-const global attributes that expect to be underscored.
> Pylint is wrong here.

Ok, forget my previous post - now I looked a bit deeper into it again. 
Consider this as an example:

# Global mouse states = global constants:
M_LEFT = 1

class somethingWork:
     """ OpenGL something class """

     def __init__(self, someInputFile):
         self.inputFile = someInputFile
         self.running = False
         # self.viewport = (800,600)
         self.viewport = (1024, 768)
         self.lightDone = False
         self.rx = 0 # rotation x
         self.ry = 0 # rotation y
         self.rz = 0 # rotation z
         .... etc ...

What pylint says is:

1) class somethingWork: Invalid name "somethingWork" (should match 
[A-Z_][a-zA-Z0-9]+$), I'm not that good at regular exps, but I suppose 
it wants my class name to start with a capital letter ?

2) self.lightDone: Invalid name "lightDone" (should match 

So I can now understand that pylint doesn't like my naming convention 
with a capital letter in the middle of the variable name, like: 
"lightDone" = a boolean value. I suppose pylint wants me to use (a 
little longer method) an underscore to separate words in long variable 

3) self.rx / rself.ry / self.rz: Invalid name "rx" (should match 
[a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an 
underscore ?

I have a lot of these warnings...

> The double-leading-and-trailing-underscore naming scheme is reserved for
> Python itself. PEP 8 explicitly states not to invent your own "dunder"
> names:
>    __double_leading_and_trailing_underscore__: "magic" objects or
>    attributes that live in user-controlled namespaces. E.g. __init__,
>    __import__ or __file__. Never invent such names; only use them as
>    documented.

I think I would also never use __something__ names...

> The section on global variables does not say to use dunder names:

Thanks a lot for this reference...

> If pylint says that global variables should be named like "__variable__",
> that is explicitly going against PEP 8.

I don't think that is what it's saying... But I think it wants me to use 
more underscores, i.e. self.lightDone => self.light_done I think...

>> You shouldn't have to use those underscores very often.  After all,
>> there is seldom a need for a non-const global value, right?  Don't think
>> of it as a pylint problem, but as a hint from pylint that perhaps you
>> should use fewer globals.
> That at least is good advice.

Ok, sorry for my previous post. This post better explains how I've named 
my variables. I don't like it complains about a simple and good variable 
name as self.rx, self.ry, self.rz and so on. These are IMHO very good 
variable names: rotation about x, y and z. Short and precise/accurate. 
I'm not sure if I'll agree with all the warnings it comes up with. But I 
think I could maybe introduce more use of underscores in the middle of 
my variable names, in the future...

Thanks for the extra + good explanations.

More information about the Python-list mailing list