-
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
Add global
and nonlocal
formatting
#6170
Conversation
|
||
f.join_with(format_args![text(","), space()]) | ||
.entries(item.names.iter().formatted()) | ||
.finish() |
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.
Straightforward I think because the grammar is so limited here? These have to be identifiers, and they can't contain any content in-between.
PR Check ResultsBenchmarkLinux
Windows
|
Line-breaking behavior in #6172. |
Do we care about DRYing this up? If so, what would be the right home for that? |
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.
Thank you. I'm surprised that there are no black tests...
Do we care about DRYing this up? If so, what would be the right home for that?
I do, for more complex implementation but the abstraction would probably require significantly more code than what we would safe.
The way I would re-use the code here is by creating a FormatNames
struct inside either of the file that accepts the names and implements Format
.
161ed4a
to
066f371
Compare
## 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.
Summary
Adds
global
andnonlocal
formatting, without the "deviation from black" outlined in the linked issue, which I'll do separately.See: #4798.
Test Plan
Added a fixture in the Ruff-specific directory since the Black fixtures don't seem to cover this.