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

Remove newlines after def #3033

Closed
saroad2 opened this issue Apr 24, 2022 · 1 comment
Closed

Remove newlines after def #3033

saroad2 opened this issue Apr 24, 2022 · 1 comment
Labels
F: empty lines Wasting vertical space efficiently. T: style What do we want Blackened code to look like?

Comments

@saroad2
Copy link
Contributor

saroad2 commented Apr 24, 2022

TL;DR

There shouldn't be a newline right after def statement.

Describe the style change

Newlines are great. They help us organize our code and leave room for the coders and reviewers to breath.
However, too many newlines can make simple code gigantic and massive. This is unnecessary in a lot of cases.

I want to argue that having a newline right after def is redundant and Black should remove it

Examples in the current Black style

Right now Black won't change the following code:

def f():

    print("No newline above me!")

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

Desired style

Black should change the code above to:

def f():
    print("No newline above me!")

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

What about classes?

I think that the issue above is not relevant to classes.

A new line after a class definition makes sense to me, since there is no actual meaning for the methods definitions order.

The newline after class definition makes room for the reader to breath before diving in to each method of the class.

So, Black should not change the following code:

class MyClass:

    def the_newline_above_me_should_stay(self):
        print("Leave the newline alone!")
@saroad2 saroad2 added the T: style What do we want Blackened code to look like? label Apr 24, 2022
@JelleZijlstra JelleZijlstra added the F: empty lines Wasting vertical space efficiently. label Apr 24, 2022
@JelleZijlstra
Copy link
Collaborator

Duplicate of #902.

For what it's worth I think this is a reasonable idea; feel free to submit a PR.

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

2 participants