mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Add dangling comment handling for lambda
expressions (#7493)
## Summary This PR adds dangling comment handling for `lambda` expressions. In short, comments around the `lambda` and the `:` are all considered dangling. Comments that come between the `lambda` and the `:` may be moved after the colon for simplicity (this is an odd position for a comment anyway), unless they also precede the lambda parameters, in which case they're formatted before the parameters. Closes https://github.com/astral-sh/ruff/issues/7470. ## Test Plan `cargo test` No change in similarity. Before: | project | similarity index | total files | changed files | |--------------|------------------:|------------------:|------------------:| | cpython | 0.76083 | 1789 | 1632 | | django | 0.99982 | 2760 | 37 | | transformers | 0.99957 | 2587 | 398 | | twine | 1.00000 | 33 | 0 | | typeshed | 0.99983 | 3496 | 18 | | warehouse | 0.99929 | 648 | 16 | | zulip | 0.99962 | 1437 | 22 | After: | project | similarity index | total files | changed files | |--------------|------------------:|------------------:|------------------:| | cpython | 0.76083 | 1789 | 1632 | | django | 0.99982 | 2760 | 37 | | transformers | 0.99957 | 2587 | 398 | | twine | 1.00000 | 33 | 0 | | typeshed | 0.99983 | 3496 | 18 | | warehouse | 0.99929 | 648 | 16 | | zulip | 0.99962 | 1437 | 22 |
This commit is contained in:
parent
e07670ad97
commit
4c4eceee36
5 changed files with 310 additions and 33 deletions
|
@ -152,4 +152,54 @@ lambda *x\
|
|||
x: x
|
||||
)
|
||||
|
||||
lambda: ( # comment
|
||||
x)
|
||||
|
||||
(
|
||||
lambda: # comment
|
||||
x
|
||||
)
|
||||
|
||||
(
|
||||
lambda:
|
||||
# comment
|
||||
x
|
||||
)
|
||||
|
||||
(
|
||||
lambda # comment
|
||||
:
|
||||
x
|
||||
)
|
||||
|
||||
(
|
||||
lambda
|
||||
# comment
|
||||
:
|
||||
x
|
||||
)
|
||||
|
||||
(
|
||||
lambda: # comment
|
||||
( # comment
|
||||
x
|
||||
)
|
||||
)
|
||||
|
||||
(
|
||||
lambda # 1
|
||||
# 2
|
||||
x # 3
|
||||
# 4
|
||||
: # 5
|
||||
# 6
|
||||
x
|
||||
)
|
||||
|
||||
(
|
||||
lambda
|
||||
x,
|
||||
# comment
|
||||
y:
|
||||
z
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue