ruff/crates/ruff_python_formatter/src
Brent Westbrook f3714fd3c1
Fix leading comment formatting for lambdas with multiple parameters (#21879)
## Summary

This is a follow-up to #21868. As soon as I started merging #21868 into
#21385, I realized that I had missed a test case with `**kwargs` after
the `*args` parameter. Such a case is supposed to be formatted on one
line like:

```py
# input
(
    lambda
    # comment
    *x,
    **y: x
)

# output
(
    lambda
    # comment
    *x, **y: x
)
```

which you can still see on the
[playground](https://play.ruff.rs/bd88d339-1358-40d2-819f-865bfcb23aef?secondary=Format),
but on `main` after #21868, this was formatted as:

```py
(
    lambda
    # comment
    *x,
    **y: x
)
```

because the leading comment on the first parameter caused the whole
group around the parameters to break.

Instead of making these comments leading comments on the first
parameter, this PR makes them leading comments on the parameters list as
a whole.

## Test Plan

New tests, and I will also try merging this into #21385 _before_ opening
it for review this time.

<hr>

(labeling `internal` since #21868 should not be released before some
kind of fix)
2025-12-09 18:15:12 -05:00
..
comments Fix leading comment formatting for lambdas with multiple parameters (#21879) 2025-12-09 18:15:12 -05:00
expression Fix leading comment formatting for lambdas with multiple parameters (#21879) 2025-12-09 18:15:12 -05:00
module [ty] AST garbage collection (#18482) 2025-06-13 08:40:11 -04:00
other Respect `fmt: skip` for compound statements on single line (#20633) 2025-11-18 12:02:09 -06:00
pattern Avoid extra parentheses for long `match` patterns with `as` captures (#21176) 2025-11-03 17:06:52 -05:00
snapshots Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
statement Respect `fmt: skip` for compound statements on single line (#20633) 2025-11-18 12:02:09 -06:00
string Avoid reusing nested, interpolated quotes before Python 3.12 (#20930) 2025-10-17 08:49:16 -04:00
type_param [ty] AST garbage collection (#18482) 2025-06-13 08:40:11 -04:00
builders.rs Implement template strings (#17851) 2025-05-30 15:00:56 -05:00
cli.rs Remove parentheses around multiple exception types on Python 3.14+ (#20768) 2025-10-14 11:17:45 -04:00
context.rs Move `Token`, `TokenKind` and `Tokens` to `ruff-python-ast` (#21760) 2025-12-02 20:10:46 +01:00
db.rs Update Rust toolchain to 1.88 and MSRV to 1.86 (#19011) 2025-06-28 20:24:00 +02:00
generated.rs Implement template strings (#17851) 2025-05-30 15:00:56 -05:00
lib.rs Update Rust toolchain to 1.91 (#21179) 2025-11-01 01:50:58 +00:00
main.rs Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
options.rs [`ruff`] Update schemars to v1 (#20942) 2025-10-20 08:59:52 +02:00
prelude.rs Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
preview.rs Avoid extra parentheses for long `match` patterns with `as` captures (#21176) 2025-11-03 17:06:52 -05:00
range.rs [ty] AST garbage collection (#18482) 2025-06-13 08:40:11 -04:00
shared_traits.rs Upgrade Rust toolchain to 1.83 (#14677) 2024-11-29 12:05:05 +00:00
verbatim.rs Move `Token`, `TokenKind` and `Tokens` to `ruff-python-ast` (#21760) 2025-12-02 20:10:46 +01:00