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:
Charlie Marsh 2023-08-07 12:36:02 -04:00 committed by GitHub
parent c895252aae
commit daefa74e9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
91 changed files with 375 additions and 1478 deletions

View file

@ -5,9 +5,6 @@ use ruff_python_ast::Stmt;
pub(crate) mod stmt_ann_assign;
pub(crate) mod stmt_assert;
pub(crate) mod stmt_assign;
pub(crate) mod stmt_async_for;
pub(crate) mod stmt_async_function_def;
pub(crate) mod stmt_async_with;
pub(crate) mod stmt_aug_assign;
pub(crate) mod stmt_break;
pub(crate) mod stmt_class_def;
@ -40,7 +37,6 @@ impl FormatRule<Stmt, PyFormatContext<'_>> for FormatStmt {
fn fmt(&self, item: &Stmt, f: &mut PyFormatter) -> FormatResult<()> {
match item {
Stmt::FunctionDef(x) => x.format().fmt(f),
Stmt::AsyncFunctionDef(x) => x.format().fmt(f),
Stmt::ClassDef(x) => x.format().fmt(f),
Stmt::Return(x) => x.format().fmt(f),
Stmt::Delete(x) => x.format().fmt(f),
@ -48,11 +44,9 @@ impl FormatRule<Stmt, PyFormatContext<'_>> for FormatStmt {
Stmt::AugAssign(x) => x.format().fmt(f),
Stmt::AnnAssign(x) => x.format().fmt(f),
Stmt::For(x) => x.format().fmt(f),
Stmt::AsyncFor(x) => x.format().fmt(f),
Stmt::While(x) => x.format().fmt(f),
Stmt::If(x) => x.format().fmt(f),
Stmt::With(x) => x.format().fmt(f),
Stmt::AsyncWith(x) => x.format().fmt(f),
Stmt::Match(x) => x.format().fmt(f),
Stmt::Raise(x) => x.format().fmt(f),
Stmt::Try(x) => x.format().fmt(f),