How do I disable “missing docstring” warnings at a

2020-02-16 06:31发布

Pylint throws errors that some of 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 a docstring at the beginning of it. 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 of 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.)

标签: python pylint
8条回答
贼婆χ
2楼-- · 2020-02-16 07:08
Edit "C:\Users\Your User\AppData\Roaming\Code\User\settings.json" and add 
python.linting.pylintArgs lines at the end as shown below:

{
    "team.showWelcomeMessage": false,
    "python.dataScience.sendSelectionToInteractiveWindow": true,
    "git.enableSmartCommit": true,
    "powershell.codeFormatting.useCorrectCasing": true,
    "files.autoSave": "onWindowChange",
    "python.linting.pylintArgs": [
        "--load-plugins=pylint_django",
        "--errors-only"
    ],
}
查看更多
叼着烟拽天下
3楼-- · 2020-02-16 07:11

Just put the following lines at the beginning of any file you want to disable these warnings.

# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
查看更多
Deceive 欺骗
4楼-- · 2020-02-16 07:13

It's late, but still I found it useful. So sharing. 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!

查看更多
欢心
5楼-- · 2020-02-16 07:15

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 eg. http://hackerboss.com/get-rid-of-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 what I suggest is 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).

查看更多
不美不萌又怎样
6楼-- · 2020-02-16 07:22

No. Pylint doesn't currently let you discriminate between doc-string warnings.

However, you can use flake8 for all python code checking along with the doc-string extension to ignore this warning.

Install the doc-string extension with pip (Internally, It uses pydocstyle).

pip install flake8_docstrings

You can then just use the --ignore D100 switch. For example flake8 file.py --ignore D100

查看更多
Evening l夕情丶
7楼-- · 2020-02-16 07:28

I think the fix is relative easy without disabling this feature.

def kos_root():
    """Return the pathname of the KOS root directory."""
    global _kos_root
    if _kos_root: return _kos_root

All you need to do is add the triple double quotes string in every function.

查看更多
登录 后发表回答