-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use one line between top-level items if formatting a stub file #6501
Conversation
PR Check ResultsBenchmarkLinux
Windows
|
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/top_level.pyi
Outdated
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