-
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
Insert empty line between suite and alternative branch after def/class #12294
Conversation
|
bd40982
to
ba1f552
Compare
When there is a function or class definition at the end of a suite followed by the beginning of an alternative block, we have to insert a single empty line between them. In the if-else-statement example below, we insert an empty line after the `foo` in the if-block, but none after the else-block `foo`, since in the latter case the enclosing suite already adds empty lines. ```python if sys.version_info >= (3, 10): def foo(): return "new" else: def foo(): return "old" class Bar: pass ``` To do so, we track whether the current suite is the last one in the current statement with a new option on the suite kind. Fixes #12199
ba1f552
to
b3d6adb
Compare
Not sure if this counts as bugfix or breaking change, i'm fine with merging it before the next breaking release. |
I think we have to gate this behind preview according to our version policy. The version policy only allows formatting style changes that address instabilities or formatting that lead to invalid syntax. The ecosystem checks look good :) |
438001a
to
5f4f4d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and thanks for working on this!
This overall looks good to me. We should add a few tests around suppression comments to make sure we don't add new lines into suppressed ranges
crates/ruff_python_formatter/src/other/except_handler_except_handler.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: Micha Reiser <[email protected]>
When there is a function or class definition at the end of a suite followed by the beginning of an alternative block, we have to insert a single empty line between them.
In the if-else-statement example below, we insert an empty line after the
foo
in the if-block, but none after the else-blockfoo
, since in the latter case the enclosing suite already adds empty lines.To do so, we track whether the current suite is the last one in the current statement with a new option on the suite kind.
Fixes #12199