From 95301b3bc96c9db59dd2d80960a5e26e43fdc09a Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Fri, 12 Dec 2025 11:39:19 -0500 Subject: [PATCH] improve after_parameters_end_of_line name and docs --- .../src/expression/expr_lambda.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/ruff_python_formatter/src/expression/expr_lambda.rs b/crates/ruff_python_formatter/src/expression/expr_lambda.rs index 36353112ff..faab6ef8c5 100644 --- a/crates/ruff_python_formatter/src/expression/expr_lambda.rs +++ b/crates/ruff_python_formatter/src/expression/expr_lambda.rs @@ -276,8 +276,8 @@ impl Format> for FormatBody<'_> { let body_comments = comments.leading_dangling_trailing(body); if !dangling_header_comments.is_empty() { - // Can't use partition_point because there can be additional end of line comments - // after the initial set. All of these comments are dangling, for example: + // Split the dangling header comments into trailing comments formatted with the lambda + // header (1) and leading comments formatted with the body (2, 3, 4). // // ```python // ( @@ -289,8 +289,9 @@ impl Format> for FormatBody<'_> { // ) // ``` // - // and alternate between own line and end of line. - let (after_parameters_end_of_line, leading_body_comments) = dangling_header_comments + // Note that these are split based on their line position rather than using + // `partition_point` based on a range, for example. + let (trailing_header_comments, leading_body_comments) = dangling_header_comments .split_at( dangling_header_comments .iter() @@ -331,7 +332,8 @@ impl Format> for FormatBody<'_> { trailing_comments(dangling_header_comments).fmt(f)?; // Note that `leading_body_comments` have already been formatted as part of - // `dangling` above, but their presence still determines the spacing here. + // `dangling_header_comments` above, but their presence still determines the spacing + // here. if leading_body_comments.is_empty() { space().fmt(f)?; } else { @@ -345,7 +347,7 @@ impl Format> for FormatBody<'_> { [ space(), token("("), - trailing_comments(after_parameters_end_of_line), + trailing_comments(trailing_header_comments), block_indent(&format_args!( leading_comments(leading_body_comments), body.format().with_options(Parentheses::Never)