black icon indicating copy to clipboard operation
black copied to clipboard

The latest behavior of empty lines is NOT reflected in the current code style documentation

Open FanchenBao opened this issue 2 years ago • 0 comments

Is this related to a problem? Please describe.

There has been some back-and-forth regarding empty line after code block open recently. The latest behavior is to keep zero empty line if that is the case in the original input, or one empty line if the original input has more than one empty lines.

However, this behavior is NOT reflected in the documented code style on empty lines. In the documentation, it is stated that

The other exception is that it will remove any empty lines immediately following a statement that introduces a new indentation level.

This is no longer true. Consequently, the given example is also incorrect, as all the empty lines after code block open are shown to be deleted after formatting.

Describe the solution you'd like

I would like the documentation to emphasize the current code style of empty line by rewriting the "The other exception is that...new indentation level" sentence. In addition, I would like the example on the empty line code style to be as follows

# in

def foo():




    print("One new line above me will be kept!")





def bar():
    print("The original input has no new line above me; we will keep it that way.")




if condition:




    print("One new line above me will be kept!")

    print("There is a newline above me, and that's OK!")





class Point:




    x: int
    y: int

# out

# out
def foo():

    print("One new line above me will be kept!")


def bar():
    print("The original input has no new line above me; we will keep it that way.")


if condition:

    print("One new line above me will be kept!")

    print("There is a newline above me, and that's OK!")


class Point:

    x: int
    y: int

Describe alternatives you've considered

NA

Additional context

NA

FanchenBao avatar Feb 18 '24 21:02 FanchenBao