Reputation: 7170
Disabling a Pylint check or getting around one of its warnings, should not be without a clear reason. I would like to be able to comment these reasons at the place I'm disabling it; so far, without success.
As an example, let a class with just a constructor and a single method. The kind of thing Pylint warns about with reasons, while there may be as much good reasons to disable this warning locally.
class Foo(object): # pylint: disable=R0903 --- Closure object
def __init__(self, data):
…
def single_method(argument):
…
With the above, Pylint not only still warns about “too few public methods” but even additionally complains about “bad option value 'R0903 --- Closure object'”.
The question has a wider rational than this single example (may be I'm not aware of a better way to achieve closures in Python), and I would like to be able to comment most of these in‑line directives, on the same line, for clarity, and simplicity. By the way, may also be useful to remind about what an option is for. As an example, reminding # pylint: disable=R0903 --- Too few public methods
(to stay on the same example).
In less words: is there a way to comment Pylint in‑line directives?
Upvotes: 8
Views: 2469
Reputation: 11929
Since pylint 1.5.0, you can do # pylint: disable=no-member; any text here
.
Upvotes: 9
Reputation: 1594
This works for me:
class Foo(object): # (Closure object) pylint: disable=R0903
def __init__(self, data):
…
def single_method(argument):
…
My pylint version is
(doisub)> $ pylint --version
pylint 1.5.4,
astroid 1.4.4
Python 2.7.11 (default, Dec 22 2015, 11:45:03)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]
Upvotes: 2
Reputation: 11730
Pylint does not support commenting directives. But starting with 0.25.3, you can use the symbolic names http://docs.pylint.org/faq.html#do-i-have-to-remember-all-these-numbers. If you need/ want the comment, you will have to use a second line (I usually add comments above my Pylint directives)
Upvotes: 0