mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:26 +00:00
Make Parameters
an optional field on ExprLambda
(#6669)
## Summary If a lambda doesn't contain any parameters, or any parameter _tokens_ (like `*`), we can use `None` for the parameters. This feels like a better representation to me, since, e.g., what should the `TextRange` be for a non-existent set of parameters? It also allows us to remove several sites where we check if the `Parameters` is empty by seeing if it contains any arguments, so semantically, we're already trying to detect and model around this elsewhere. Changing this also fixes a number of issues with dangling comments in parameter-less lambdas, since those comments are now automatically marked as dangling on the lambda. (As-is, we were also doing something not-great whereby the lambda was responsible for formatting dangling comments on the parameters, which has been removed.) Closes https://github.com/astral-sh/ruff/issues/6646. Closes https://github.com/astral-sh/ruff/issues/6647. ## Test Plan `cargo test`
This commit is contained in:
parent
ea72d5feba
commit
6a5acde226
30 changed files with 517 additions and 412 deletions
|
@ -56,12 +56,16 @@ lambda x: lambda y: lambda z: (
|
|||
z) # Trailing
|
||||
# Trailing
|
||||
|
||||
|
||||
a = (
|
||||
lambda # Dangling
|
||||
: 1
|
||||
)
|
||||
|
||||
a = (
|
||||
lambda x # Dangling
|
||||
, y: 1
|
||||
)
|
||||
|
||||
# Regression test: lambda empty arguments ranges were too long, leading to unstable
|
||||
# formatting
|
||||
(lambda:(#
|
||||
|
@ -93,3 +97,24 @@ lambda a, *args, b, **kwds,: 0
|
|||
lambda a, *, b, **kwds,: 0
|
||||
lambda a, /: a
|
||||
lambda a, /, c: a
|
||||
|
||||
# Dangling comments without parameters.
|
||||
(
|
||||
lambda
|
||||
: # 3
|
||||
None
|
||||
)
|
||||
|
||||
(
|
||||
lambda
|
||||
# 3
|
||||
: None
|
||||
)
|
||||
|
||||
(
|
||||
lambda # 1
|
||||
# 2
|
||||
: # 3
|
||||
# 4
|
||||
None # 5
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue