diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/named_expr.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/named_expr.py index 2b9d0ade31..0d9b8e366c 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/named_expr.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/named_expr.py @@ -47,6 +47,13 @@ if ( ): pass +if ( + x # 2 + := # 3 + y +): + pass + y0 = (y1 := f(x)) f(x:=y, z=True) diff --git a/crates/ruff_python_formatter/src/expression/expr_named_expr.rs b/crates/ruff_python_formatter/src/expression/expr_named_expr.rs index 0d2ac80fc7..98aeb4ceff 100644 --- a/crates/ruff_python_formatter/src/expression/expr_named_expr.rs +++ b/crates/ruff_python_formatter/src/expression/expr_named_expr.rs @@ -75,7 +75,7 @@ impl NeedsParentheses for ExprNamedExpr { { OptionalParentheses::Always } else { - OptionalParentheses::Never + OptionalParentheses::Multiline } } } diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__named_expr.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__named_expr.py.snap index 95a899f8f2..68a74972a0 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__named_expr.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__named_expr.py.snap @@ -53,6 +53,13 @@ if ( ): pass +if ( + x # 2 + := # 3 + y +): + pass + y0 = (y1 := f(x)) f(x:=y, z=True) @@ -149,6 +156,13 @@ if ( ): pass +if ( + x # 2 + := # 3 + y +): + pass + y0 = (y1 := f(x)) f(x := y, z=True)