Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pylint disabling a single line of code just produces another pylint error

Tags:

python

pylint

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?

like image 910
David Parks Avatar asked Jan 04 '23 02:01

David Parks


2 Answers

I have been in a similar situation.

Unsolvable pylint issue

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.

Unavoidable bad-option-value

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.

Disable bad-option-value

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.

like image 107
Yan QiDong Avatar answered Jan 05 '23 15:01

Yan QiDong


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)
like image 27
David Parks Avatar answered Jan 05 '23 16:01

David Parks