Skip to content

One space between class definition and the first inner method #619

@cmin764

Description

@cmin764

Can Black have a rule to not remove the whitespace at line 2 from here:

class C:
    
    def __init__(self):
        pass

so that it will keep the blank line between class definition and any first inner entity (as it does already with the docstrings and assignment attributes)?

It's extremely ugly to have that whitespace consistent in the entire codebase and just in this particular situation, where you don't have anything to add between class definition and the first inner method (which usually is the __init__ one), to end up with "glued" headers of class and method definition.

Now if I'm formatting this:

class C:
    
    def __init__(self):
        pass
    def func(self):
        pass

I get this:

class C:
    def __init__(self):
        pass

    def func(self):
        pass

So I expect the rule of one empty line before and after class methods to be consistent here. Everyone likes to have symmetry in their code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: empty linesWasting vertical space efficiently.R: rejectedThis will not be worked onS: needs discussionNeeds further hashing out before ready for implementation (on desirability, feasibility, etc.)T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions