mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 04:55:09 +00:00
Force parentheses for named expressions in more contexts (#6494)
See: https://github.com/astral-sh/ruff/pull/6436#issuecomment-1673583888.
This commit is contained in:
parent
2e5c81b202
commit
2cedb401bd
3 changed files with 48 additions and 0 deletions
|
@ -36,3 +36,18 @@ except (e := Exception):
|
||||||
(x := 1)
|
(x := 1)
|
||||||
|
|
||||||
(x := 1) + (y := 2)
|
(x := 1) + (y := 2)
|
||||||
|
|
||||||
|
with (x := 1):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def f():
|
||||||
|
yield (x := 1)
|
||||||
|
|
||||||
|
|
||||||
|
def f():
|
||||||
|
yield from (x := 1)
|
||||||
|
|
||||||
|
|
||||||
|
async def f():
|
||||||
|
await (x := 1)
|
||||||
|
|
|
@ -44,6 +44,9 @@ impl NeedsParentheses for ExprNamedExpr {
|
||||||
|| parent.is_stmt_return()
|
|| parent.is_stmt_return()
|
||||||
|| parent.is_except_handler_except_handler()
|
|| parent.is_except_handler_except_handler()
|
||||||
|| parent.is_with_item()
|
|| parent.is_with_item()
|
||||||
|
|| parent.is_expr_yield()
|
||||||
|
|| parent.is_expr_yield_from()
|
||||||
|
|| parent.is_expr_await()
|
||||||
|| parent.is_stmt_delete()
|
|| parent.is_stmt_delete()
|
||||||
|| parent.is_stmt_for()
|
|| parent.is_stmt_for()
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,21 @@ except (e := Exception):
|
||||||
(x := 1)
|
(x := 1)
|
||||||
|
|
||||||
(x := 1) + (y := 2)
|
(x := 1) + (y := 2)
|
||||||
|
|
||||||
|
with (x := 1):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def f():
|
||||||
|
yield (x := 1)
|
||||||
|
|
||||||
|
|
||||||
|
def f():
|
||||||
|
yield from (x := 1)
|
||||||
|
|
||||||
|
|
||||||
|
async def f():
|
||||||
|
await (x := 1)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
@ -82,6 +97,21 @@ except (e := Exception):
|
||||||
(x := 1)
|
(x := 1)
|
||||||
|
|
||||||
(x := 1) + (y := 2)
|
(x := 1) + (y := 2)
|
||||||
|
|
||||||
|
with (x := 1):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def f():
|
||||||
|
yield (x := 1)
|
||||||
|
|
||||||
|
|
||||||
|
def f():
|
||||||
|
yield from (x := 1)
|
||||||
|
|
||||||
|
|
||||||
|
async def f():
|
||||||
|
await (x := 1)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue