Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
# 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...