Remove Expr postfix from ExprNamed, ExprIf, and ExprGenerator (#10229)

The expression types in our AST are called `ExprYield`, `ExprAwait`,
`ExprStringLiteral` etc, except `ExprNamedExpr`, `ExprIfExpr` and
`ExprGenratorExpr`. This seems to align with [Python AST's
naming](https://docs.python.org/3/library/ast.html) but feels
inconsistent and excessive.

This PR removes the `Expr` postfix from `ExprNamedExpr`, `ExprIfExpr`,
and `ExprGeneratorExpr`.
This commit is contained in:
Micha Reiser 2024-03-04 12:55:01 +01:00 committed by GitHub
parent 8b749e1d4d
commit 184241f99a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
64 changed files with 418 additions and 428 deletions

View file

@ -656,7 +656,7 @@ pub struct ExprBoolOp<'a> {
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct ExprNamedExpr<'a> {
pub struct ExprNamed<'a> {
target: Box<ComparableExpr<'a>>,
value: Box<ComparableExpr<'a>>,
}
@ -681,7 +681,7 @@ pub struct ExprLambda<'a> {
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct ExprIfExp<'a> {
pub struct ExprIf<'a> {
test: Box<ComparableExpr<'a>>,
body: Box<ComparableExpr<'a>>,
orelse: Box<ComparableExpr<'a>>,
@ -718,7 +718,7 @@ pub struct ExprDictComp<'a> {
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct ExprGeneratorExp<'a> {
pub struct ExprGenerator<'a> {
elt: Box<ComparableExpr<'a>>,
generators: Vec<ComparableComprehension<'a>>,
}
@ -832,17 +832,17 @@ pub struct ExprIpyEscapeCommand<'a> {
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum ComparableExpr<'a> {
BoolOp(ExprBoolOp<'a>),
NamedExpr(ExprNamedExpr<'a>),
NamedExpr(ExprNamed<'a>),
BinOp(ExprBinOp<'a>),
UnaryOp(ExprUnaryOp<'a>),
Lambda(ExprLambda<'a>),
IfExp(ExprIfExp<'a>),
IfExp(ExprIf<'a>),
Dict(ExprDict<'a>),
Set(ExprSet<'a>),
ListComp(ExprListComp<'a>),
SetComp(ExprSetComp<'a>),
DictComp(ExprDictComp<'a>),
GeneratorExp(ExprGeneratorExp<'a>),
GeneratorExp(ExprGenerator<'a>),
Await(ExprAwait<'a>),
Yield(ExprYield<'a>),
YieldFrom(ExprYieldFrom<'a>),
@ -889,11 +889,11 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
op: (*op).into(),
values: values.iter().map(Into::into).collect(),
}),
ast::Expr::NamedExpr(ast::ExprNamedExpr {
ast::Expr::Named(ast::ExprNamed {
target,
value,
range: _,
}) => Self::NamedExpr(ExprNamedExpr {
}) => Self::NamedExpr(ExprNamed {
target: target.into(),
value: value.into(),
}),
@ -923,12 +923,12 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
parameters: parameters.as_ref().map(Into::into),
body: body.into(),
}),
ast::Expr::IfExp(ast::ExprIfExp {
ast::Expr::If(ast::ExprIf {
test,
body,
orelse,
range: _,
}) => Self::IfExp(ExprIfExp {
}) => Self::IfExp(ExprIf {
test: test.into(),
body: body.into(),
orelse: orelse.into(),
@ -973,12 +973,12 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
value: value.into(),
generators: generators.iter().map(Into::into).collect(),
}),
ast::Expr::GeneratorExp(ast::ExprGeneratorExp {
ast::Expr::Generator(ast::ExprGenerator {
elt,
generators,
range: _,
parenthesized: _,
}) => Self::GeneratorExp(ExprGeneratorExp {
}) => Self::GeneratorExp(ExprGenerator {
elt: elt.into(),
generators: generators.iter().map(Into::into).collect(),
}),