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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With