Remove parentheses around some walrus operators#6173
Conversation
| if x := 1: | ||
| pass | ||
|
|
||
| (x := 1) |
There was a problem hiding this comment.
I'm trying to figure out why the parentheses aren't being removed here (which is correct, but parent.is_stmt_expr() isn't in the conditional).
There was a problem hiding this comment.
Parentheses are only removed in statements other than ExprStmt (and only for top-level expressions).
ruff/crates/ruff_python_formatter/src/statement/stmt_expr.rs
Lines 16 to 20 in 40f5437
The formatting calls expr.format() which preserves parentheses.
(I wonder if we can remove the arithmetic handling now too).
| if x := 1: | ||
| pass | ||
|
|
||
| (x := 1) |
There was a problem hiding this comment.
Parentheses are only removed in statements other than ExprStmt (and only for top-level expressions).
ruff/crates/ruff_python_formatter/src/statement/stmt_expr.rs
Lines 16 to 20 in 40f5437
The formatting calls expr.format() which preserves parentheses.
(I wonder if we can remove the arithmetic handling now too).
PR Check ResultsBenchmarkLinuxWindows |
Summary
Closes #5781
Test Plan
Added cases to
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/named_expr.pyone-by-one and adjusted the condition as needed.