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

Stubs: black removes empty lines between attributes and methods #2706

Closed
srittau opened this issue Dec 17, 2021 · 3 comments · Fixed by #2736
Closed

Stubs: black removes empty lines between attributes and methods #2706

srittau opened this issue Dec 17, 2021 · 3 comments · Fixed by #2736
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

@srittau
Copy link
Contributor

srittau commented Dec 17, 2021

Please consider the following un-blacked stub file:

class Foo:
    x: int
    y: int

    a: int
    b: int

    def bar(self) -> int: ...
    def baz(self) -> int: ...

In this case, the empty line between attributes and methods is intentional as is the empty line between the attribute blocks. black 21.12b0 (no special config) changes this to:

class Foo:
    x: int
    y: int

    a: int
    b: int
    def bar(self) -> int: ...
    def baz(self) -> int: ...

Desired style

I believe that black should keep one blank line between attributes and methods if there is at least one blank line in the source. This can aid readability for classes with many attributes/methods.

@srittau srittau added the T: style What do we want Blackened code to look like? label Dec 17, 2021
@Petar-Iliev
Copy link

I tried to reproduce this and black kept the blank line.

class Foo:
    x: int
    y: int

    a: int
    b: int

    def bar(self) -> int:
        pass

    def baz(self) -> int:
        pass

@JelleZijlstra
Copy link
Collaborator

@Petar-Iliev did you try with --pyi? I agree that we should keep this blank line even in stubs.

@JelleZijlstra JelleZijlstra added F: empty lines Wasting vertical space efficiently. S: accepted The changes in this design / enhancement issue have been accepted and can be implemented labels Dec 20, 2021
@Petar-Iliev
Copy link

Petar-Iliev commented Dec 20, 2021

@JelleZijlstra with --pyi it's removing the blank line, my bad I didn't saw the 'stub' part

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.

3 participants