Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pylint

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?

like image 894
Hibou57 Avatar asked Sep 01 '14 16:09

Hibou57


People also ask

How do you get Pylint to ignore a line?

you can ignore it by adding a comment in the format # pylint: disable=[problem-code] at the end of the line where [problem-code] is the value inside pylint(...) in the pylint message – for example, abstract-class-instantiated for the problem report listed above.


2 Answers

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

like image 179
The Compiler Avatar answered Nov 11 '22 11:11

The Compiler


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)]
like image 30
Tom Barron Avatar answered Nov 11 '22 11:11

Tom Barron