PyCQA / pydocstyle

docstring style checker
http://pydocstyle.org
MIT License
1.11k stars 189 forks source link

Newline after docstring/Usefulness of D202 #504

Closed LinqLover closed 2 years ago

LinqLover commented 4 years ago

PEP257 says:

Insert a blank line after all docstrings (one-line or multi-line) that document a class -- generally speaking, the class's methods are separated from each other by a single blank line, and the docstring needs to be offset from the first method by a blank line.

(emphasis mine)

As I understand this, every method containing a docstring should be formatted like this:

def foo():
    """
    My wonderful docstring.
    """

    return 42

However, this raises "D202 No blank lines allowed after function docstring". I could suppress this warning, but instead, I would like to get an error if I miss the newline after docstring:

def foo():
    """
    My docstring missing a trailing newline!
    """
    return 42

Has this already been discussed in this repository? Would it be possible to add an option for being warned about such missing newlines?

sigmavirus24 commented 4 years ago

Has this already been discussed in this repository?

To varying degrees it has, usually while discussing other codes https://github.com/PyCQA/pydocstyle/issues?q=is%3Aissue+d202

e-gebes commented 2 years ago

There is a misunderstanding of PEP257. It mentions, that after a class docstring there should be a blank line before the first method.

An example for this would be:

class Foo:
    """
    My wonderful class docstring. A blank line shall follow.
    """

    def first_method(self):
        ...

I think this can be closed.

mcara commented 1 year ago

Why would an empty line outside of docstrings be of any concern for pydocstyle?

sigmavirus24 commented 1 year ago

Because the tool tries to implement the style recommendations of PEP 257 which if look a few comments above describes whitespace around the docstring.

mcara commented 1 year ago

There’s no blank line either before or after the docstring.

This note from PEP 257 is mentioned in relation to one-line docstrings. It is not obvious it applies to multi-line strings.

sigmavirus24 commented 1 year ago

I'm not here to debate arbitrary excerpts from a document that's likely evolved since this tool was created. You asked a snarky and bad faith question about why this tool cares, I answered you. This tool has backwards compatibility guarantees and so trying to keep up with the fickle desires of the PEP editors isn't entirely plausible, it's why checks can be disabled or enabled at will.