Fix formatting lambda with empty arguments (#5944)

**Summary** Fix implemented in
https://github.com/astral-sh/RustPython-Parser/pull/35: Previously,
empty lambda arguments (e.g. `lambda: 1`) would get the range of the
entire expression, which leads to incorrect comment placement. Now empty
lambda arguments get an empty range between the `lambda` and the `:`
tokens.

**Test Plan** Added a regression test.

149 instances of unstable formatting remaining.

```
$ cargo run --bin ruff_dev --release -- format-dev --stability-check --error-file formatter-ecosystem-errors.txt --multi-project target/checkouts > formatter-ecosystem-progress.txt
$ rg "Unstable formatting" target/formatter-ecosystem-errors.txt | wc -l
149
```
This commit is contained in:
konsti 2023-07-21 15:48:45 +02:00 committed by GitHub
parent 519dbdffaa
commit 972f9a9c15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 14 deletions

View file

@ -60,4 +60,9 @@ z) # Trailing
a = (
lambda # Dangling
: 1
)
)
# Regression test: lambda empty arguments ranges were too long, leading to unstable
# formatting
(lambda:(#
),)

View file

@ -66,7 +66,13 @@ z) # Trailing
a = (
lambda # Dangling
: 1
)```
)
# Regression test: lambda empty arguments ranges were too long, leading to unstable
# formatting
(lambda:(#
),)
```
## Output
```py
@ -130,6 +136,13 @@ lambda x: lambda y: lambda z: (
a = (
lambda: 1 # Dangling
)
# Regression test: lambda empty arguments ranges were too long, leading to unstable
# formatting
(
lambda: ( #
),
)
```