Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python code convention using pylint

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_]*)|(__.*__))$)

like image 607
Jack Ha Avatar asked Apr 02 '09 12:04

Jack Ha


People also ask

What is pylint used for in Python?

Pylint analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells, and can make suggestions about how the code could be refactored. Pylint can infer actual values from your code using its internal code representation (astroid).

What standard does pylint use?

Pylint is a Python tool that checks a module for coding standards. According to the TurboGears project coding guidelines, PEP8 is the standard and pylint is a good mechanical test to help us in attaining that goal.


2 Answers

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

like image 131
alex Avatar answered Nov 15 '22 13:11

alex


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 ...
like image 38
Jason Coon Avatar answered Nov 15 '22 13:11

Jason Coon