mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Break global and nonlocal statements over continuation lines (#6172)
## Summary Builds on #6170 to break `global` and `nonlocal` statements, such that we get: ```python def f(): global \ analyze_featuremap_layer, \ analyze_featuremapcompression_layer, \ analyze_latencies_post, \ analyze_motions_layer, \ analyze_size_model ``` Instead of: ```python def f(): global analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model ``` Notably, we avoid applying this formatting if the statement ends in a comment. Otherwise, the comment would _need_ to be placed after the last item, like: ```python def f(): global \ analyze_featuremap_layer, \ analyze_featuremapcompression_layer, \ analyze_latencies_post, \ analyze_motions_layer, \ analyze_size_model # noqa ``` To me, this seems wrong (and would break the `# noqa` comment). Ideally, the items would be parenthesized, and the comment would be on the inner parenthesis, like: ```python def f(): global ( # noqa analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model ) ``` But that's not valid syntax.
This commit is contained in:
parent
9f38dbd06e
commit
9425ed72a0
6 changed files with 114 additions and 10 deletions
|
@ -10,3 +10,7 @@ def f():
|
|||
|
||||
def f():
|
||||
global analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model
|
||||
|
||||
|
||||
def f():
|
||||
global analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model # end-of-line comment
|
||||
|
|
|
@ -10,3 +10,7 @@ def f():
|
|||
|
||||
def f():
|
||||
nonlocal analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model
|
||||
|
||||
|
||||
def f():
|
||||
nonlocal analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model # end-of-line comment
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue