Use one line between top-level items if formatting a stub file#6501
Use one line between top-level items if formatting a stub file#6501MichaReiser merged 22 commits intoastral-sh:mainfrom
Conversation
PR Check ResultsBenchmarkLinuxWindows |
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/top_level.pyi
Show resolved
Hide resolved
That sounds reasonable. We'll need to change all call sites (because they currently always wrap the body in a |
Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: Micha Reiser <micha@reiser.io>
|
Turns out this doesn't deal with leading comments. For example, it formats to class Load(expr_context):
...
# Some comment.
class Other(expr_context):
...I assumed this wouldn't happen because it deals with leading comments in non-stub files. For example, class Load(expr_context):
...
# Some comment.
class Other(expr_context):
... |
|
This change improves the typeshed similarity index from 0.74233 to 0.74261 |
|
Thank you! Do you want to look into the body formatting of when it is a single |
I'll take a look at it. |
Summary
When formatting stub files, use only one line between top-level items. Use zero lines between class definitions of the same type that have an empty body (nothing but
...). Closes #5821.This PR doesn't implement moving the ellipsis to the same line as the class definition signature. I have never touched the formatter code before, so was looking around about how to do it and found #5822. Seeing as it has its own issue, I might just leave it out of this PR.
Test Plan
cargo test