mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:10 +00:00
Format named expressions (walrus operator) (#5642)
## Summary Format named expressions (walrus operator) such a `value := f()`. Unlike tuples, named expression parentheses are not part of the range even when mandatory, so mapping optional parentheses to always gives us decent formatting without implementing all [PEP 572](https://peps.python.org/pep-0572/) rules on when we need parentheses where other expressions wouldn't. We might want to revisit this decision later and implement special cases, but for now this gives us what we need. ## Test Plan black fixtures, i added some fixtures and checked django and cpython for stability. Closes #5613
This commit is contained in:
parent
1e894f328c
commit
bd8f65814c
8 changed files with 152 additions and 318 deletions
13
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/named_expr.py
vendored
Normal file
13
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/named_expr.py
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
y = 1
|
||||
|
||||
if (
|
||||
# 1
|
||||
x # 2
|
||||
:= # 3
|
||||
y # 4
|
||||
):
|
||||
pass
|
||||
|
||||
y0 = (y1 := f(x))
|
||||
|
||||
f(x:=y, z=True)
|
Loading…
Add table
Add a link
Reference in a new issue