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

Blank lines before class docstring are not removed #3659

Closed
jonathanberthias opened this issue Apr 24, 2023 · 3 comments · Fixed by #3692
Closed

Blank lines before class docstring are not removed #3659

jonathanberthias opened this issue Apr 24, 2023 · 3 comments · Fixed by #3692
Labels
F: empty lines Wasting vertical space efficiently. S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: style What do we want Blackened code to look like?

Comments

@jonathanberthias
Copy link
Contributor

Describe the style change

The blank lines between a function's definition and its docstring currently get removed by Black. However, it does not do the same thing for classes.

Current Black changes

def f():

    """The line above gets removed."""
    return 0

becomes

def f():
    """The line above gets removed."""
    return 0

but

class C:

    """The line above stays."""

is not modified by Black.

Desired style

I would have expected that code to get reformatted as:

class C:
    """The line above stays."""
@jonathanberthias jonathanberthias added the T: style What do we want Blackened code to look like? label Apr 24, 2023
@huzaifakhan771
Copy link

huzaifakhan771 commented Apr 27, 2023

This seems like the intended behavior. I tested it by adding more than one blank line after class definition, and it changed it to one line.

For example:

class C:



    """The line above stays."""

becomes

class C:

    """The line above stays."""

However, if I don't have any blank lines at all, it doesn't change it.

For example:

class C:
    """The line above stays."""

stays

class C:
    """The line above stays."""

So if the intended behavior is to have one blank line after class definition, it should stay consistent.

@st-pasha
Copy link

I agree with the OP that Black should enforce a consistent style in this case. There is no reason for a blank line to exist between a class/function declaration and the subsequent docstring.

@JelleZijlstra JelleZijlstra added the F: empty lines Wasting vertical space efficiently. label Apr 29, 2023
@JelleZijlstra
Copy link
Collaborator

Agree, let's remove these blank lines.

@JelleZijlstra JelleZijlstra added the S: accepted The changes in this design / enhancement issue have been accepted and can be implemented label Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: empty lines Wasting vertical space efficiently. S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: style What do we want Blackened code to look like?
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants