Search code examples
pythoncoding-stylepylint

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?


Solution

  • 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.