From 4d76cd7b1579c3934835cf5d9cbe7f437a438e5e Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Fri, 5 Dec 2025 14:57:54 -0500 Subject: [PATCH] factor out parameters_have_comments --- crates/ruff_python_formatter/src/expression/expr_lambda.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ruff_python_formatter/src/expression/expr_lambda.rs b/crates/ruff_python_formatter/src/expression/expr_lambda.rs index 6248573789..65c2f574ed 100644 --- a/crates/ruff_python_formatter/src/expression/expr_lambda.rs +++ b/crates/ruff_python_formatter/src/expression/expr_lambda.rs @@ -31,6 +31,8 @@ impl FormatNodeRule for FormatExprLambda { write!(f, [token("lambda")])?; if let Some(parameters) = parameters { + let parameters_have_comments = comments.contains_comments(parameters.as_ref().into()); + // In this context, a dangling comment can either be a comment between the `lambda` and the // parameters, or a comment between the parameters and the body. let (dangling_before_parameters, dangling_after_parameters) = dangling @@ -43,7 +45,7 @@ impl FormatNodeRule for FormatExprLambda { } // Try to keep the parameters on a single line, unless there are intervening comments. - if preview && !comments.contains_comments(parameters.as_ref().into()) { + if preview && !parameters_have_comments { let mut buffer = RemoveSoftLinesBuffer::new(f); write!( buffer,