Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.6.0-rc2 - Emtpy Lines After Docstring and Before Nested Function Definition Are Removed #161

Closed
rmartin16 opened this issue Jan 31, 2023 · 8 comments · Fixed by #175
Closed
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: enhancement Feature that is outside the scope of PEP 257
Milestone

Comments

@rmartin16
Copy link

#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:

 def test_no_git(tracking_create_command, monkeypatch):
     """If Git is not installed, an error is raised."""
-
     def monkeypatch_verify_git(*a, **kw):
         raise BriefcaseCommandError("Briefcase requires git, but it is not installed")
@github-actions github-actions bot added the fresh This is a new issue label Jan 31, 2023
@weibullguy
Copy link
Member

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.

@weibullguy weibullguy added P: enhancement Feature that is outside the scope of PEP 257 C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) and removed fresh This is a new issue labels Jan 31, 2023
@weibullguy weibullguy modified the milestones: v2.0.0, v1.7.0 Mar 20, 2023
@bonastreyair
Copy link

bonastreyair commented Apr 4, 2023

I've added another example here: #130 (comment)

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"

@weibullguy
Copy link
Member

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

@Kurt-von-Laven
Copy link

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.

@drasmuss
Copy link

drasmuss commented Apr 4, 2023

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.

@weibullguy
Copy link
Member

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

@jonyscathe
Copy link

v1.6.1-rc1 fixes this issue for me

@bonastreyair
Copy link

@weibullguy it works for mee too yup! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: enhancement Feature that is outside the scope of PEP 257
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants