How to comment / document uses of Pylint in‑line options?

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?


Since pylint 1.5.0, you can do # pylint: disable=no-member; any text here.

Leave a Reply

Your email address will not be published. Required fields are marked *