Pylint throws errors that some of the files are missing docstrings. I try and add docstrings to each class, method and function, but it seems that Pylint also checks that files should have a docstring at the beginning of them. Can I disable this somehow?
I would like to be notified of a docstring is missing inside a class, function or method, but it shouldn't be mandatory for a file to have a docstring.
(Is there a term for the legal jargon often found at the beginning of a proprietary source file? Any examples? I don't know whether it is a okay to post such a trivial question separately.)
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.
This may be done by adding # pylint: disable=some-message,another-one at the desired block level or at the end of the desired line of code.
Module docstrings are similar to class docstrings. Instead of classes and class methods being documented, it's now the module and any functions found within. Module docstrings are placed at the top of the file even before any imports.
All functions should have a docstring. Accessing Docstrings: The docstrings can be accessed using the __doc__ method of the object or using the help function.
It is nice for a Python module to have a docstring, explaining what the module does, what it provides, examples of how to use the classes. This is different from the comments that you often see at the beginning of a file giving the copyright and license information, which IMO should not go in the docstring (some even argue that they should disappear altogether, see e.g. Get Rid of Source Code Templates)
With Pylint 2.4 and above, you can differentiate between the various missing-docstring
by using the three following sub-messages:
C0114
(missing-module-docstring
)C0115
(missing-class-docstring
)C0116
(missing-function-docstring
)So the following .pylintrc
file should work:
[MASTER] disable= C0114, # missing-module-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. The problem is that if you disable this at module scope, then it will be disabled everywhere in the module (i.e., you won't get any C line for missing function / class / method docstring. Which arguably is not nice.
So I suggest adding that small missing docstring, saying something like:
""" high level support for doing this and that. """
Soon enough, you'll be finding useful things to put in there, such as providing examples of how to use the various classes / functions of the module which do not necessarily belong to the individual docstrings of the classes / functions (such as how these interact, or something like a quick start guide).
[Updated on 21 Dec 2021]
As mentioned by followben in the comments, a better solution is to just disable the rules that we want to disable rather than using --errors-only
.
This can be done by adding this in settings:
"python.linting.pylintArgs": ["--disable=C0111"]
[Old answer]
I found this here.
You can add "--errors-only" flag for Pylint to disable warnings.
To do this, go to settings. Edit the following line:
"python.linting.pylintArgs": []
As
"python.linting.pylintArgs": ["--errors-only"]
And you are good to go!
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