Skip to content

Decorated classes below functions aren't separated with blank lines in .pyi files #18865

@bzoracler

Description

@bzoracler

Summary

In a stub.pyi, I expect a blank line before a class (including its decorators) when it's defined below a function.

Before formatting:

def hello(): ...

@lambda _, /: _
class A: ...

After formatting:

def hello(): ...
@lambda _, /: _
class A: ...

For reference, the blank line is added by the formatter when the class sits below other statements, like imports, assignments, and other classes.

(I couldn't provide a ruff playground link because I couldn't figure out how to make it format a source file like it would do for stubs. Does such an option in the playground exist?)


See psf/black#4256 for reference - the missing blank line isn't intentional, but fixing it in black is apparently not trivial. Is it also not trivial in ruff?

Version

ruff 0.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    formatterRelated to the formattergood first issueGood for newcomershelp wantedContributions especially welcomestyleHow should formatted code look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions