mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-13 16:15:07 +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
|
@ -1,5 +1,5 @@
|
|||
// auto-generated: "lalrpop 0.20.0"
|
||||
// sha3: e2b75c2709648429269934006c032842f6800678baccab09dedfb746463c30b4
|
||||
// sha3: 6ec03d3255ad27917601bff9ad0b1df5f8702124139879a78e7dca689ca1b113
|
||||
use num_bigint::BigInt;
|
||||
use ruff_text_size::TextSize;
|
||||
use ruff_python_ast::{self as ast, Ranged, IpyEscapeKind};
|
||||
|
@ -35817,7 +35817,7 @@ fn __action184<
|
|||
(_, location, _): (TextSize, TextSize, TextSize),
|
||||
(_, _, _): (TextSize, token::Tok, TextSize),
|
||||
(_, location_args, _): (TextSize, TextSize, TextSize),
|
||||
(_, p, _): (TextSize, core::option::Option<ast::Parameters>, TextSize),
|
||||
(_, parameters, _): (TextSize, core::option::Option<ast::Parameters>, TextSize),
|
||||
(_, end_location_args, _): (TextSize, TextSize, TextSize),
|
||||
(_, _, _): (TextSize, token::Tok, TextSize),
|
||||
(_, body, _): (TextSize, ast::Expr, TextSize),
|
||||
|
@ -35825,13 +35825,11 @@ fn __action184<
|
|||
) -> Result<ast::Expr,__lalrpop_util::ParseError<TextSize,token::Tok,LexicalError>>
|
||||
{
|
||||
{
|
||||
p.as_ref().map(validate_arguments).transpose()?;
|
||||
let p = p
|
||||
.unwrap_or_else(|| ast::Parameters::empty((location_args..end_location_args).into()));
|
||||
parameters.as_ref().map(validate_arguments).transpose()?;
|
||||
|
||||
Ok(ast::Expr::Lambda(
|
||||
ast::ExprLambda {
|
||||
parameters: Box::new(p),
|
||||
parameters: parameters.map(Box::new),
|
||||
body: Box::new(body),
|
||||
range: (location..end_location).into()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue