-
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
[pyupgrade
] Unwrap unary expressions correctly (UP018
)
#15919
base: main
Are you sure you want to change the base?
Conversation
|
Another case to consider is |
(Some(Expr::Attribute(_)), LiteralType::Float, true) => format!("({arg_code})"), | ||
|
||
( | ||
Some( |
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.
Could we reuse the Precedence
infrastructure introduced in #15762 over implementing the correct precedence manually here?
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.
I'm not sure how to use that OperatorPrecedence
to differentiate foo(int(-1))
and int(-1)()
.
By the way, there are now four OperatorPrecedence
s around the codebase: two in the formatter, one in the parser and one in the linter.
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.
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.
Couldn't we use the precedence to represent int
's position? I think it's: For the second it's CallAttribute
, for the first it's parenthesized (may require adding a new operator precedence)
Summary
Resolves #15859.
The rule now adds parentheses if the original call wraps an unary expression and is:
**
.The fix will also be marked as unsafe if there are any comments in its range.
Test Plan
cargo nextest run
andcargo insta test
.