mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 15:47:41 +00:00
Don't format trailing comma for lambda arguments (#5946)
**Summary** lambda arguments don't have parentheses, so they shouldn't get a magic trailing comma either. This fixes some unstable formatting **Test Plan** Added a regression test. 89 (from previously 145) 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 89 ``` Closes #5892
This commit is contained in:
parent
40f54375cb
commit
06d9ff9577
5 changed files with 126 additions and 28 deletions
|
@ -72,6 +72,15 @@ a = (
|
|||
# formatting
|
||||
(lambda:(#
|
||||
),)
|
||||
|
||||
# lambda arguments don't have parentheses, so we never add a magic trailing comma ...
|
||||
def f(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = lambda x: y,
|
||||
):
|
||||
pass
|
||||
|
||||
# ...but we do preserve a trailing comma after the arguments
|
||||
a = lambda b,: 0
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -143,6 +152,17 @@ a = (
|
|||
lambda: ( #
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
# lambda arguments don't have parentheses, so we never add a magic trailing comma ...
|
||||
def f(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = lambda x: y,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
# ...but we do preserve a trailing comma after the arguments
|
||||
a = lambda b,: 0
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,13 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic
|
|||
"seventh entry",
|
||||
"eighth entry",
|
||||
)
|
||||
|
||||
# Regression test: Respect setting in Arguments formatting
|
||||
def f(a): pass
|
||||
def g(a,): pass
|
||||
|
||||
x1 = lambda y: 1
|
||||
x2 = lambda y,: 1
|
||||
```
|
||||
|
||||
## Outputs
|
||||
|
@ -56,6 +63,21 @@ magic-trailing-comma = Respect
|
|||
"seventh entry",
|
||||
"eighth entry",
|
||||
)
|
||||
|
||||
|
||||
# Regression test: Respect setting in Arguments formatting
|
||||
def f(a):
|
||||
pass
|
||||
|
||||
|
||||
def g(
|
||||
a,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
x1 = lambda y: 1
|
||||
x2 = lambda y,: 1
|
||||
```
|
||||
|
||||
|
||||
|
@ -82,6 +104,19 @@ magic-trailing-comma = Ignore
|
|||
"seventh entry",
|
||||
"eighth entry",
|
||||
)
|
||||
|
||||
|
||||
# Regression test: Respect setting in Arguments formatting
|
||||
def f(a):
|
||||
pass
|
||||
|
||||
|
||||
def g(a):
|
||||
pass
|
||||
|
||||
|
||||
x1 = lambda y: 1
|
||||
x2 = lambda y,: 1
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue