mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Avoid extra parentheses in unary expressions (#7428)
## Summary This PR applies a similar fix to unary expressions as in https://github.com/astral-sh/ruff/pull/7424. Specifically, we only need to parenthesize the entire operator if the operand itself doesn't have parentheses, and requires parentheses. Closes https://github.com/astral-sh/ruff/issues/7423. ## Test Plan `cargo test` No change in similarity. Before: | project | similarity index | total files | changed files | |--------------|------------------:|------------------:|------------------:| | cpython | 0.76083 | 1789 | 1632 | | django | 0.99982 | 2760 | 37 | | transformers | 0.99957 | 2587 | 399 | | twine | 1.00000 | 33 | 0 | | typeshed | 0.99983 | 3496 | 18 | | warehouse | 0.99923 | 648 | 18 | | zulip | 0.99962 | 1437 | 22 | After: | project | similarity index | total files | changed files | |--------------|------------------:|------------------:|------------------:| | cpython | 0.76083 | 1789 | 1632 | | django | 0.99982 | 2760 | 37 | | transformers | 0.99957 | 2587 | 399 | | twine | 1.00000 | 33 | 0 | | typeshed | 0.99983 | 3496 | 18 | | warehouse | 0.99923 | 648 | 18 | | zulip | 0.99962 | 1437 | 22 |
This commit is contained in:
parent
0d1fb823d6
commit
1880cceac1
3 changed files with 34 additions and 4 deletions
|
@ -157,6 +157,16 @@ if (
|
|||
not # comment
|
||||
a):
|
||||
...
|
||||
|
||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7423
|
||||
if True:
|
||||
if True:
|
||||
if True:
|
||||
if not yn_question(
|
||||
Fore.RED
|
||||
+ "WARNING: Removing listed files. Do you really want to continue. yes/n)? "
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -323,10 +333,18 @@ if (
|
|||
):
|
||||
...
|
||||
|
||||
if (
|
||||
not a # comment
|
||||
):
|
||||
if not a: # comment
|
||||
...
|
||||
|
||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7423
|
||||
if True:
|
||||
if True:
|
||||
if True:
|
||||
if not yn_question(
|
||||
Fore.RED
|
||||
+ "WARNING: Removing listed files. Do you really want to continue. yes/n)? "
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue