mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-14 08:35:08 +00:00
Remove async AST node variants for with
, for
, and def
(#6369)
## Summary Per the suggestion in https://github.com/astral-sh/ruff/discussions/6183, this PR removes `AsyncWith`, `AsyncFor`, and `AsyncFunctionDef`, replacing them with an `is_async` field on the non-async variants of those structs. Unlike an interpreter, we _generally_ have identical handling for these nodes, so separating them into distinct variants adds complexity from which we don't really benefit. This can be seen below, where we get to remove a _ton_ of code related to adding generic `Any*` wrappers, and a ton of duplicate branches for these cases. ## Test Plan `cargo test` is unchanged, apart from parser snapshots.
This commit is contained in:
parent
c895252aae
commit
daefa74e9a
91 changed files with 375 additions and 1478 deletions
|
@ -1,5 +1,5 @@
|
|||
// auto-generated: "lalrpop 0.20.0"
|
||||
// sha3: f99d8cb29227bfbe1fa07719f655304a9a93fd4715726687ef40c091adbdbad5
|
||||
// sha3: d713a7771107f8c20353ce5e890fba004b3c5491f513d28e9348a49cd510c59b
|
||||
use num_bigint::BigInt;
|
||||
use ruff_text_size::TextSize;
|
||||
use ruff_python_ast::{self as ast, Ranged, MagicKind};
|
||||
|
@ -33081,11 +33081,7 @@ fn __action147<
|
|||
.end();
|
||||
let target = Box::new(set_context(target, ast::ExprContext::Store));
|
||||
let iter = Box::new(iter);
|
||||
if is_async.is_some() {
|
||||
ast::Stmt::AsyncFor(ast::StmtAsyncFor { target, iter, body, orelse, range: (location..end_location).into() })
|
||||
} else {
|
||||
ast::Stmt::For(ast::StmtFor { target, iter, body, orelse, range: (location..end_location).into() })
|
||||
}
|
||||
ast::Stmt::For(ast::StmtFor { target, iter, body, orelse, is_async: is_async.is_some(), range: (location..end_location).into() })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33306,11 +33302,7 @@ fn __action155<
|
|||
{
|
||||
{
|
||||
let end_location = body.last().unwrap().end();
|
||||
if is_async.is_some() {
|
||||
ast::StmtAsyncWith { items, body, range: (location..end_location).into() }.into()
|
||||
} else {
|
||||
ast::StmtWith { items, body, range: (location..end_location).into() }.into()
|
||||
}
|
||||
ast::StmtWith { items, body, is_async: is_async.is_some(), range: (location..end_location).into() }.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33407,11 +33399,7 @@ fn __action161<
|
|||
let args = Box::new(args);
|
||||
let returns = r.map(Box::new);
|
||||
let end_location = body.last().unwrap().end();
|
||||
if is_async.is_some() {
|
||||
ast::StmtAsyncFunctionDef { name, parameters:args, body, decorator_list, returns, type_params, range: (location..end_location).into() }.into()
|
||||
} else {
|
||||
ast::StmtFunctionDef { name, parameters:args, body, decorator_list, returns, type_params, range: (location..end_location).into() }.into()
|
||||
}
|
||||
ast::StmtFunctionDef { name, parameters:args, body, decorator_list, returns, type_params, is_async: is_async.is_some(), range: (location..end_location).into() }.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue