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

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

Closed
FanchenBao opened this issue Feb 18, 2024 · 0 comments · Fixed by #4239
Closed
Labels
T: documentation Improvements to the docs (e.g. new topic, correction, etc)

Comments

@FanchenBao
Copy link

FanchenBao commented Feb 18, 2024

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 FanchenBao added the T: documentation Improvements to the docs (e.g. new topic, correction, etc) label Feb 18, 2024
@FanchenBao FanchenBao changed the title The current behavior of empty lines is NOT reflected in the current code style documentation The latest behavior of empty lines is NOT reflected in the current code style documentation Feb 18, 2024
hauntsaninja added a commit to hauntsaninja/black that referenced this issue Feb 18, 2024
Reflects status quo following psf#4043

Fixes psf#4238
hauntsaninja added a commit that referenced this issue Feb 26, 2024
Reflects status quo following #4043

Fixes #4238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: documentation Improvements to the docs (e.g. new topic, correction, etc)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant