Insert empty line between suite and alternative branch after def/class#12294
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
MichaReiser
left a comment
There was a problem hiding this comment.
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
Co-authored-by: Micha Reiser <micha@reiser.io>
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
fooin 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