You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Decorated classes below functions aren't separated with blank lines in .pyi files #18865
formatterRelated to the Ruff formattergood first issueAn issue good for human newcomershelp wantedContributions especially welcomestyleHow should Ruff-formatted code look
In a stub.pyi, I expect a blank line before a class (including its decorators) when it's defined below a function.
Before formatting:
defhello(): ...
@lambda_, /: _classA: ...
After formatting:
defhello(): ...
@lambda_, /: _classA: ...
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?
formatterRelated to the Ruff formattergood first issueAn issue good for human newcomershelp wantedContributions especially welcomestyleHow should Ruff-formatted code look
Activity
MichaReiser commentedon Jun 23, 2025
That makes sense to me. I think that should be fairly easy to change. It might be as easy as removing
ruff/crates/ruff_python_formatter/src/statement/suite.rs
Lines 693 to 706 in 9ae698f
We would need to gate the change behind preview mode because we can only release it as part of the next minor. See https://github.com/astral-sh/ruff/blob/1aad180aae84cd5d12d5a47c879183f559c871ed/crates/ruff_python_formatter/src/preview.rs#L1-L0 for a few exmaples on how to do that