Handle right parens in join comma builder#5711
Merged
MichaReiser merged 1 commit intomainfrom Jul 12, 2023
Merged
Conversation
Member
Author
|
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
MichaReiser
commented
Jul 12, 2023
|
|
||
| func_with_bad_parens_that_wont_fit_in_one_line( | ||
| "short string that should have parens stripped", x, y, z | ||
| ("short string that should have parens stripped"), x, y, z |
Member
Author
There was a problem hiding this comment.
I tested this locally, black preserves the parentheses, regardless of what the text says
Contributor
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinuxWindows |
konstin
approved these changes
Jul 12, 2023
|
|
||
| func_with_bad_parens_that_wont_fit_in_one_line( | ||
| "short string that should have parens stripped", x, y, z | ||
| ("short string that should have parens stripped"), x, y, z |
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
The
JoinCommaSeparatedBuilderonly tested if the first token after the node is a,.However, this always fails for expressions with parentheses, because the parentheses are not part of the expression's range.
This PR changes the
JoinCommaSeparatedBuilderto skip right parens. However, we need to be careful, becausenested(call(arg),)only the outer call has a trailing commain this example, not the inner arg. The way this is implemented is by also passing an approxiamted end of the sequence (normally the end of the enclosing node, but we don't always know precisely), and only search between the end of the last node and the end of the sequence.
I further went along and also fixed an issue where single argument call expressions were always parenthesized because
is_expression_parenthesizeddoesn't know that the parens from the arguments belong to the call. The way to solve this is by handling parenthesesmanually inside of
FormatCallExprif the call only has a single argument.Test Plan
See updated snapshot tests.