How do I disable “missing docstring” warnings at a file-level in Pylint?

前端 未结 11 640
情书的邮戳
情书的邮戳 2020-12-12 14:18

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 s

相关标签:
11条回答
  • 2020-12-12 14:34

    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
    
    0 讨论(0)
  • 2020-12-12 14:37

    I came looking for an answer because, as @cerin said, in Django projects it is cumbersome and redundant to add module docstrings to every one of the files that django automatically generates when creating a new app.

    So, as a workaround for the fact that pylint doesn't let you specify a difference in docstring types, you can do this:

    pylint */*.py --msg-template='{path}: {C}:{line:3d},{column:2d}: {msg}' | grep docstring | grep -v module
    

    You have to update the msg-template so that when you grep you will still know the file name. This returns all the other missing-docstring types excluding modules.

    Then you can fix all of those errors, and afterwards just run:

    pylint */*.py --disable=missing-docstring
    
    0 讨论(0)
  • 2020-12-12 14:37

    (1) CTRL+SHIFT+P (2)Then type and click on >preferences:configure language specific settings (3)and then type python after that past the code

    {
    "python.linting.pylintArgs": [
        "--load-plugins=pylint_django","--errors-only"
    ],
    
    }
    
    0 讨论(0)
  • 2020-12-12 14:41

    Go to "settings.json" and disable python pydocstyle

    "python.linting.pydocstyleEnabled": false
    
    0 讨论(0)
  • 2020-12-12 14:49

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

    0 讨论(0)
  • 2020-12-12 14:49

    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

    0 讨论(0)
提交回复
热议问题