Only omit optional parentheses for starting or ending with parentheses#8238
Merged
MichaReiser merged 2 commits intomainfrom Oct 26, 2023
Conversation
Member
Author
|
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
84532b9 to
2b676e8
Compare
| .first | ||
| .expression() | ||
| .is_some_and(|first| is_parenthesized(first, context)) | ||
| } |
Member
There was a problem hiding this comment.
I tend to write this as:
if first_condition {
return true;
}
if second_condition {
return true;
}
falseBut it's extremely personal 😂
| if op.is_invert() { | ||
| self.update_max_precedence(OperatorPrecedence::BitwiseInversion); | ||
| } | ||
| self.first.set_if_none(First::Token); |
Member
There was a problem hiding this comment.
Is this correct for all unary operators?
Member
Author
There was a problem hiding this comment.
All unary operators come before the operand, so I think yes. Like +(a, b, c) doesn't start with a ( but with +
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
This PR fixes a black deviation where Ruff omitted parentheses for expressions that don't end with a parenthesized expression
but the "first" node was parenthesized:
Ruff ommitted parentheses for this expression because it assumed that the expression starts with
(aaaaa...(bbbb, ccc)which is parenthesized.However, this is incorrect. The expression starts with the
notkeyword which isn't a parentheses and Ruff should thus add parentheses.Closes #8183
Test Plan
Added tests.
PR
main