From d1b79f5400f0b66beaea205a41e06ab76b32ea5e Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Thu, 11 Dec 2025 15:13:47 -0500 Subject: [PATCH] share common code --- .../src/expression/expr_lambda.rs | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/crates/ruff_python_formatter/src/expression/expr_lambda.rs b/crates/ruff_python_formatter/src/expression/expr_lambda.rs index fa18dc6b3a..70fcb84039 100644 --- a/crates/ruff_python_formatter/src/expression/expr_lambda.rs +++ b/crates/ruff_python_formatter/src/expression/expr_lambda.rs @@ -409,25 +409,15 @@ impl Format> for FormatBody<'_> { if is_expression_parenthesized((*body).into(), comments.ranges(), f.context().source()) && comments.has_leading(*body) { + trailing_comments(dangling).fmt(f)?; + if leading_body_comments.is_empty() { - write!( - f, - [ - space(), - trailing_comments(dangling), - body.format().with_options(Parentheses::Always), - ] - ) + space().fmt(f)?; } else { - write!( - f, - [ - trailing_comments(dangling), - hard_line_break(), - body.format().with_options(Parentheses::Always) - ] - ) + hard_line_break().fmt(f)?; } + + body.format().with_options(Parentheses::Always).fmt(f) } else { write!( f,