Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell PyLint "it's a variable, not a constant" to stop message C0103?

Tags:

python

pylint

I have a module-level variable in my Python 2.6 program named "_log", which PyLint complains about:

C0103: Invalid name "_log" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)

Having read this answer I understand why it's doing this: it thinks the variable is a constant and applies the constant regex. However, I beg to differ: I think it's a variable. How do I tell PyLint that, so it doesn't complain? How does PyLint determine whether it's a variable or a constant - does it just treat all module-level variables as constants?

like image 327
EMP Avatar asked Dec 11 '09 01:12

EMP


People also ask

How do I ignore Pylint errors?

This may be done by adding # pylint: disable=some-message,another-one at the desired block level or at the end of the desired line of code.

What is C in Pylint?

OUTPUT Using the default text output, the message format is : MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE There are 5 kind of message types : * (C) convention, for programming standard violation * (R) refactor, for bad code smell * (W) warning, for python specific problems * (E) error, for probable bugs in the code * (F) ...

How do I know if a Pylint is ignoring a file?

The solution was to include --disable=file-ignored in the Pylint command options.


2 Answers

# pylint: disable-msg=C0103 

Put it in the scope where you want these warnings to be ignored. You can also make the above an end-of-line comment, to disable the message only for that line of code.

IIRC it is true that pylint interprets all module-level variables as being 'constants'.

newer versions of pylint will take this line instead

# pylint: disable=C0103 
like image 133
ChristopheD Avatar answered Oct 18 '22 20:10

ChristopheD


You can also specify a comma separated list of "good-names" that are always allowed in your pylintrc, eg:

[BASIC]
good-names=_log
like image 26
AdamR Avatar answered Oct 18 '22 20:10

AdamR