Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to disable pylint missing docstring error for short functions and methods?

Pylint reports an error for every function and method (except __init__) that has no docstring.

This is generally desirable, so I don't want to disable it globally (in pylintrc, or at file level).

However, in my opinion, there are cases where a docstring is not necessary, and even harmful. For example:

def get_foo(self, foo_id):
    """Gets foo by its id."""
    return foos[foo_id]

This method is a simple getter that is completely described by its signature. Having to write a docstring is harmful in that it creates duplicate maintenance if the method is changed.

I'd like to be able to set (e.g. in pylintrc) something like docstring_threshold=3, to suppress missing docstring errors if the function or method is shorter than 3 lines of code. Is there any way to do that?

like image 352
Itamar Avatar asked Nov 12 '14 14:11

Itamar


People also ask

How do I disable Pylint docstring?

For previous versions of Pylint, it does not have a separate code for the various place where docstrings can occur, so all you can do is disable C0111.

How do I ignore Pylint errors?

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.

What does missing docstring mean?

Missing function or method docstring used when a function or method has no docstring. Some special methods like __init__ , protected, private functions, setters and deleters do not require a docstring (learn more from testscases). It's a good practice to describe what a function does for other programmers.

What is a function docstring?

A docstring is simply a multi-line string, that is not assigned to anything. It is specified in source code that is used to document a specific segment of code. Unlike conventional source code comments, the docstring should describe what the function does, not how.


1 Answers

Using pylint 1.3.1 add a line to you pylintrc docstring-min-length=10 for example.

It is described in the generated pylintrc pylint --generate-rcfile file as

Minimum line length for functions/classes that require docstrings, shorter ones are exempt.

Documentation reference.

like image 187
ryanpattison Avatar answered Oct 06 '22 18:10

ryanpattison