Skip to content

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

@Rizhiy

Description

@Rizhiy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: empty linesWasting vertical space efficiently.T: styleWhat do we want Blackened code to look like?
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions