-
Notifications
You must be signed in to change notification settings - Fork 189
Allow blank lines after multi-line function docstrings #361
Comments
In our project we are using There is the case of inner functions following docstrings where pydocstyle tells me to remove the empty line after the docstring:
And then I run black, it will add the empty line back, because it puts empty lines around inner functions: To me, the Would you be willing to change D202 and make it so that this formatting is allowed and will not raise a D202?
|
Changes D202: "No blank lines allowed after function docstring" to allow space below function docstrings with inner functions. i.e. allows: ```python def outer(): """Valid docstring.""" def inner(): pass return pass ``` See comment from @cdeil in PyCQA#361. feat(checker): add test case to test_definitions docs(changelog): add change to release notes
* fix(checker): allow whitespace before inner functions and class Changes D202: ("No blank lines allowed after function docstring") to allow space below function docstrings with inner functions. i.e. allows: ```python def outer(): """Valid docstring.""" def inner(): pass return pass ``` See comment from @cdeil in #361. * fix(checker): use raw string for all regex Avoid DeprecationWarning ("invalid escape sequence").
AFAICS, this issue is fixed by #426 and could be closed. |
Actually I think this is not fully resolved: as noted in the original message, I think that a careful reading of PEP257 indicates that the prohibition for a blank link after the docstring only applies to single-line docstrings (the point literally appears in the "one-line docstrings" section). |
Faced the same problem with inner functions. I added a comment just after the docstring of outer functions and left a new line before the inner function, worked for me. |
Currently, pydocstyle warns by default when a function docstring is followed by a blank line (D202). However, a careful reading of PEP257 indicates that this rule should only apply to one-line docstrings, not to multiline docstrings: the sole sentence regarding this, "There's no blank line either before or after the docstring.", occurs in the "One-line docstrings" section, immediately after the "The closing quotes are on the same line as the opening quotes. This looks better for one-liners." sentence which clearly only applies to one-line docstrings. Allowing an empty line after the function docstring also makes sense if e.g. the function body contains empty lines: in something like
if there's no empty line after the docstring, I personally feel the docstring "binds" too closely to the first part of the body at the expense of the second part.
The text was updated successfully, but these errors were encountered: