Skip to content

Black should enforce zero empty leading lines in function body  #902

@rogalski

Description

@rogalski

Operating system: playground
Python version: playground
Black version: master

Consider following code snippet:

class X:
    
    
    def f(self, x):
        
        
        return x**2

When class definition is formatted, empty lines between class X: line and first node of the body is forced to be zero.
When function definition is formatted, empty lines between def f(): line and first node of the body is normalised to either 0 (if input code had 0 empty lines) or 1 (if input code had 1+ empty lines).

While it's preferable to preserve some of the empty lines of input code, doing this for leading empty lines of node body makes no sense, as this empty line cannot have any mental meaning in such context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: empty linesWasting vertical space efficiently.S: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions