10

I'm trying out pylint to check my source code for conventions. Somehow some variable names are matched with the regex for constants (const-rgx) instead of the variable name regex (variable-rgx). How to match the variable name with variable-rgx? Or should I extend const-rgx with my variable-rgx stuff?

e.g.
C0103: 31: Invalid name "settings" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)

SilentGhost
  • 307,395
  • 66
  • 306
  • 293
Jack Ha
  • 19,661
  • 11
  • 37
  • 41

3 Answers3

27

Somehow some variable names are matched with the regex for constants (const-rgx) instead of the variable name regex (variable-rgx).

Are those variables declared on module level? Maybe that's why they are treated as constants (at least that's how they should be declared, according to PEP-8).

alex
  • 388
  • 2
  • 5
  • 1
    +1 for answering the real question, i.e. about which regex is being used, not the actual regex. – DNS Apr 02 '09 at 14:08
  • They are indeed declared on module level! – Jack Ha Apr 02 '09 at 14:37
  • 3
    the most annoying warning comes when this check pops up in the ´if __name__ == '__main__'´ block, but it is correct since all the variables there are still on the module level. The easiest way to overcome the problem is to have only call to a separate main(...) function – van Dec 23 '09 at 10:11
10

I just disable that warning because I don't follow those naming conventions.

To do that, add this line to the top of you module:

# pylint: disable-msg=C0103

If you want to disable that globally, then add it to the pylint command:

python lint.py --disable-msg=C0103 ...
Jason Coon
  • 17,601
  • 10
  • 42
  • 50
0

(should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)

like you said that is the const-rgx that is only matching UPPERCASE names, or names surrounded by double underscores.

the variables-rgx is

([a-z_][a-z0-9_]{2,30}$)

if your variable is called 'settings' that indeed should match the variables-rgx

I can think of only 2 reasons for this.. either settings is a constant or it is a bug in PyLint.

ShoeLace
  • 3,476
  • 2
  • 30
  • 44