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

Don't insert extra blank lines at the start of an indent #3089

Closed
Rizhiy opened this issue May 27, 2022 · 4 comments
Closed

Don't insert extra blank lines at the start of an indent #3089

Rizhiy opened this issue May 27, 2022 · 4 comments
Labels
F: empty lines Wasting vertical space efficiently. T: style What do we want Blackened code to look like?

Comments

@Rizhiy
Copy link

Rizhiy commented May 27, 2022

Describe the style change

If a function/class is defined at the start of a non-scoping indent (e.g. if, for) a blank line is inserted before the function.
I would like this removed, since:

  • If an indent is scoping (e.g. def, class) no blank line is inserted and I would prefer if style was consistent.
  • I believe this is redundant since the indent already separates the function/class definition well enough.

Examples in the current Black style

# No blank lines
def f():
    def g():
        pass


class A:
    def g():
        pass


# Blank lines
for _ in range(10):

    def g():
        pass


if True:

    def g():
        pass

Desired style

# No blank lines
def f():
    def g():
        pass


class A:
    def g():
        pass


# Also, no blank lines
for _ in range(10):
    def g():
        pass


if True:
    def g():
        pass

Additional context

The issue came up when my team was developing a tool to remove blank lines at the start of indents, would be cool if black autocorrected that as well.

@Rizhiy Rizhiy added the T: style What do we want Blackened code to look like? label May 27, 2022
@JelleZijlstra JelleZijlstra added the F: empty lines Wasting vertical space efficiently. label May 27, 2022
@felix-hilden
Copy link
Collaborator

Thanks for submitting! We've pretty much agreed that this is wanted, and it's already implemented in #3035 (which started as a fix to #902). I'll link this issue as a closing target there.

@felix-hilden felix-hilden added the S: accepted The changes in this design / enhancement issue have been accepted and can be implemented label May 30, 2022
@Rizhiy
Copy link
Author

Rizhiy commented May 30, 2022

@felix-hilden I just checked #3035 and it doesn't work for my case.
Please note that my case specifically talks about function/class definition inside a block.

I believe there is another rule which enforces one blank line before function/class declaration and there is a conflict as a result.

@felix-hilden felix-hilden removed the S: accepted The changes in this design / enhancement issue have been accepted and can be implemented label May 30, 2022
@felix-hilden
Copy link
Collaborator

Right, I checked the code once more, sorry about that. The line in question I believe is this, which forces a newline if we are some blocks deep in the nesting for defs and classes.

I agree with you that after opening a block, a new line before defs and classes is pretty redundant. So after #3035 is merged, I'd be happy to include this one as well! Others?

@JelleZijlstra
Copy link
Collaborator

Duplicate of #450

@JelleZijlstra JelleZijlstra marked this as a duplicate of #450 Apr 29, 2023
@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale 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. T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

3 participants