question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Black should have an opinion about all blank lines

See original GitHub issue

Is your feature request related to a problem? Please describe.

There are a number of open issues related to handling blank lines (https://github.com/psf/black/issues/932, https://github.com/psf/black/issues/355, etc.) but I was wondering whether Black should have an opinion about all blank lines to further ensure code consistency and remove unnecessary style nits.

In addition to existing issues in relation to blank lines around comments, docstrings, etc. I wonder if Black should also be opinionated about whether blank lines should be present either preceding, within, or succeeding:

  • if statements
  • loops
  • try/except blocks
  • multiline statements
  • return statements
  • inline functions
  • etc.

Describe the solution you’d like

Personally for if statements, loops, try/except blocks, and multiline statements I prefer having a blank line preceding and succeeding the statement if the indentation level is the same, i.e.,

try:
    x = int(input())
    x2 = x ** 2
    
    y = a_multiline_statement(
        x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x
    )

    if x % 2 == 0:
        print("even")
    else:
        print("odd")

    for i in range(x):
        for j in range(x):
            if i != j:
                print(i * j)
except ValueError as e:
    print(str(e))

Describe alternatives you’ve considered None.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:6

github_iconTop GitHub Comments

2reactions
ambvcommented, Mar 3, 2020

Black used to initially have a strong opinion about all blank lines. My initial thinking was that if you need to split your functions into sections… you want more functions. But this argument proved to be extremely unpopular so I backed out of it.

And @ftruzzi, if you look at the history of the project, Black initially did put blank lines after control flow statements (return, raise, continue, and break). I like this myself but unfortunately there were annoying edge cases with it so it was not a good rule to enforce every time.

So in general, I think we won’t be doing what this request is suggesting. There are related bugs (like handling double blank lines in functions that are preceeded by a comment line; or standardizing on no blank lines after docstrings) that we might address. But we sadly cannot enforce any blanket usage of blank lines.

1reaction
JelleZijlstracommented, Jun 18, 2020

Black’s style is to put two lines between functions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove Blank Rows/Columns with Power Query Incl ...
Non-printing characters, spaces and empty strings can make it difficult to remove blank rows and ... 27K views 7 months ago Power Query....
Read more >
How to Remove Blank Lines Within Cells in Excel - YouTube
No need to write anything inside “Replace With” Option. Now click on “Replace All ”. This will remove all the line breaks and...
Read more >
The Black code style - Black 22.12.0 documentation
Empty lines #. Black avoids spurious vertical whitespace. This is in the spirit of PEP 8 which says that in-function vertical whitespace should...
Read more >
SET SQLBLANKLINES - Oracle SQL*Plus - O'Reilly
Pressing Enter on a blank line while typing a SQL statement into SQL*Plus ... without the need to go through and modify all...
Read more >
Remove unwanted empty lines - Vim Tips Wiki - Fandom
Use either of the following commands to delete all empty lines: :g/^$/d :v/. ... lines (all lines that have no characters, or that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found