Closed rmartin16 closed 1 year ago
Per PEP-257, there is no blank line either before or after a docstring. The current docformatter behavior is correct. This is an enhancement that can be added to #94.
I've added another example here: https://github.com/PyCQA/docformatter/issues/130#issuecomment-1495579567
Given:
class Foo:
@abstractmethod
def bar(self):
"""This is a description."""
@abstractmethod
def baz(self):
"""This is a second description."""
def new_function():
"""Description."""
return "bar"
I get this:
class Foo:
@abstractmethod
def bar(self):
"""This is a description."""
@abstractmethod
def baz(self):
"""This is a second description."""
def new_function():
"""Description."""
return "bar"
@bonastreyair per PEP-257, there is no blank line either before or after a docstring. Add a pass
or any other Python statement to your stub functions and the blank lines won't be removed.
docformatter v1.6.0 isn't correctly removing the blank line after a docstring in this scenario; it's incorrectly removing the docstring between method definitions. PEP 257 states:
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.
PEP 8 states:
Method definitions inside a class are surrounded by a single blank line.
docformatter shouldn't render an opinion on the use of the optional pass
keyword.
Note that this also applies to top level functions, not just class methods, e.g.
def foo():
"""Description."""
def bar():
"""Description."""
becomes
def foo():
"""Description."""
def bar():
"""Description."""
This is a pretty clear violation of pep8 (https://peps.python.org/pep-0008/#blank-lines)
Surround top-level function and class definitions with two blank lines.
I can't imagine that pep 257 was intended to override those basic pep8 blank line principles.
@bonastreyair tag v1.6.1-rc1 should have the fix you need if you're interested in giving it a try before I officially release v1.6.1.
@Kurt-von-Laven and @drasmuss you're correct, I didn't pay close enough attention to what @bonastreyair actually reported. Stub functions should be left as-is by docformatter in v1.6.1.
v1.6.1-rc1 fixes this issue for me
@weibullguy it works for mee too yup! thanks!
138 started removing empty lines after the method docstring including if the first code in the method if a function definition. I'm not sure if there should be exception for this situation...but at least
black
wants an empty line before a nested function definition.Example: