mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 04:18:05 +00:00
Avoid extra parentheses in await expressions (#7424)
## Summary This PR aligns the await parenthesizing with the unary case, which is: if the value is already parenthesized, avoid parenthesizing; otherwise, only parenthesize if the _value_ needs parenthesizing. Closes https://github.com/astral-sh/ruff/issues/7420. ## 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
1880cceac1
commit
22770fb4be
3 changed files with 71 additions and 3 deletions
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/await.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7420
|
||||
result = await self.request(
|
||||
f"/applications/{int(application_id)}/guilds/{int(scope)}/commands/{int(command_id)}/permissions"
|
||||
)
|
||||
|
||||
result = await (self.request(
|
||||
f"/applications/{int(application_id)}/guilds/{int(scope)}/commands/{int(command_id)}/permissions"
|
||||
))
|
||||
|
||||
result = await (1 + f(1, 2, 3,))
|
||||
|
||||
result = (await (1 + f(1, 2, 3,)))
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7420
|
||||
result = await self.request(
|
||||
f"/applications/{int(application_id)}/guilds/{int(scope)}/commands/{int(command_id)}/permissions"
|
||||
)
|
||||
|
||||
result = await self.request(
|
||||
f"/applications/{int(application_id)}/guilds/{int(scope)}/commands/{int(command_id)}/permissions"
|
||||
)
|
||||
|
||||
result = await (
|
||||
1
|
||||
+ f(
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
)
|
||||
)
|
||||
|
||||
result = await (
|
||||
1
|
||||
+ f(
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue