Add global and nonlocal formatting#6170
Merged
charliermarsh merged 1 commit intomainfrom Jul 29, 2023
Merged
Conversation
charliermarsh
commented
Jul 29, 2023
|
|
||
| f.join_with(format_args![text(","), space()]) | ||
| .entries(item.names.iter().formatted()) | ||
| .finish() |
Member
Author
There was a problem hiding this comment.
Straightforward I think because the grammar is so limited here? These have to be identifiers, and they can't contain any content in-between.
Contributor
PR Check ResultsBenchmarkLinuxWindows |
Member
Author
|
Line-breaking behavior in #6172. |
Member
Author
|
Do we care about DRYing this up? If so, what would be the right home for that? |
MichaReiser
approved these changes
Jul 29, 2023
Member
MichaReiser
left a comment
There was a problem hiding this comment.
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
72 tasks
charliermarsh
added a commit
that referenced
this pull request
Aug 2, 2023
## 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
globalandnonlocalformatting, 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.