Reputation: 32051
The documentation in section 4.1 clearly states:
https://pylint.readthedocs.io/en/latest/faq.html#message-control
4.1 Is it possible to locally disable a particular message?
Yes, this feature has been added in Pylint 0.11. 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
Great! but it doesn't work. Boo.
I get the the following pylint error for the following line of code
W: 26, 2: Redefining built-in 'zip' (redefined-builtin)
try:
from itertools import izip as zip # pylint: disable=bad-builtin
except ImportError:
pass
But pylint just complains even louder about my attempt to shut it up:
E: 26, 0: Bad option value 'bad-builtin' (bad-option-value)
I've also tried the error code # pylint: disable=W0141
, that also produces a similar error.
Any idea what I'm doing wrong?
Upvotes: 5
Views: 9628
Reputation: 12877
When you get this message:
W: 26, 2: Redefining built-in 'zip' (redefined-builtin)
You have to disable the exact error message you are getting (the one in parenthesis):
try:
from itertools import izip as zip # pylint: disable=redefined-builtin
except ImportError:
pass
That seems to work fine in pylint 2.5.
It can be annoying if you are testing with multiple versions of python or different venvs and the same code base and you get different errors. Be sure you fix the version to one version across all your builds/tests. It sounds like that may have happened here (not sure where you got bad-builtin
from).
Upvotes: 0
Reputation: 32051
Ah, simple answer, it should be # pylint: disable=bad-option-value
which is presented in the error message in parenthesis:
E: 26, 0: Bad option value 'bad-builtin' (bad-option-value)
Upvotes: 3
Reputation: 4421
I have been in a similar situation.
class A:
pass
There are many warnings in pylint
for the code above, but I want to talk about old-style-class
.
In Python 2.7, you will get an old-style-class
error.
Of course, you can change your code like this:
class A(object):
pass
However, you will receive a useless-object-inheritance
warning in Python 3.
If you are writing a package compatible with python 2.7 and 3 and using pylint
, then you are down.
Yes, if it is accepted to disable either of old-style-class
or useless-object-inheritance
in a comment, you can go further.
In Python 2.7:
# pylint: disable=old-style-class
class A:
pass
In Python 3:
# pylint: disable=useless-object-inheritance
class A(object):
pass
Eventually, you will get a bad-option-value
, just the same as this question.
I have tried, but bad-option-value
can not be disabled locally in this case.
I have to disable bad-option-value
in a pylint
configuration file, like .pylintrc
.
[TYPECHECK]
disable=bad-option-value
Note: My pylint
version is 1.9.4 in python 2.7, 2.2.2 in python 3.
Upvotes: 7