mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-12 07:35:07 +00:00
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:
parent
8b749e1d4d
commit
184241f99a
64 changed files with 418 additions and 428 deletions
|
@ -43,17 +43,17 @@ pub(crate) fn assignment_target(target: &Expr) -> Result<(), LexicalError> {
|
|||
};
|
||||
match *target {
|
||||
BoolOp(ref e) => Err(err(e.range.start())),
|
||||
NamedExpr(ref e) => Err(err(e.range.start())),
|
||||
Named(ref e) => Err(err(e.range.start())),
|
||||
BinOp(ref e) => Err(err(e.range.start())),
|
||||
UnaryOp(ref e) => Err(err(e.range.start())),
|
||||
Lambda(ref e) => Err(err(e.range.start())),
|
||||
IfExp(ref e) => Err(err(e.range.start())),
|
||||
If(ref e) => Err(err(e.range.start())),
|
||||
Dict(ref e) => Err(err(e.range.start())),
|
||||
Set(ref e) => Err(err(e.range.start())),
|
||||
ListComp(ref e) => Err(err(e.range.start())),
|
||||
SetComp(ref e) => Err(err(e.range.start())),
|
||||
DictComp(ref e) => Err(err(e.range.start())),
|
||||
GeneratorExp(ref e) => Err(err(e.range.start())),
|
||||
Generator(ref e) => Err(err(e.range.start())),
|
||||
Await(ref e) => Err(err(e.range.start())),
|
||||
Yield(ref e) => Err(err(e.range.start())),
|
||||
YieldFrom(ref e) => Err(err(e.range.start())),
|
||||
|
|
|
@ -17,11 +17,11 @@ pub(super) use lalrpop_util::ParseError as LalrpopError;
|
|||
|
||||
use ruff_python_ast::{
|
||||
Expr, ExprAttribute, ExprAwait, ExprBinOp, ExprBoolOp, ExprBooleanLiteral, ExprBytesLiteral,
|
||||
ExprCall, ExprCompare, ExprDict, ExprDictComp, ExprEllipsisLiteral, ExprFString,
|
||||
ExprGeneratorExp, ExprIfExp, ExprIpyEscapeCommand, ExprLambda, ExprList, ExprListComp,
|
||||
ExprName, ExprNamedExpr, ExprNoneLiteral, ExprNumberLiteral, ExprSet, ExprSetComp, ExprSlice,
|
||||
ExprStarred, ExprStringLiteral, ExprSubscript, ExprTuple, ExprUnaryOp, ExprYield,
|
||||
ExprYieldFrom, Mod, ModModule, Suite,
|
||||
ExprCall, ExprCompare, ExprDict, ExprDictComp, ExprEllipsisLiteral, ExprFString, ExprGenerator,
|
||||
ExprIf, ExprIpyEscapeCommand, ExprLambda, ExprList, ExprListComp, ExprName, ExprNamed,
|
||||
ExprNoneLiteral, ExprNumberLiteral, ExprSet, ExprSetComp, ExprSlice, ExprStarred,
|
||||
ExprStringLiteral, ExprSubscript, ExprTuple, ExprUnaryOp, ExprYield, ExprYieldFrom, Mod,
|
||||
ModModule, Suite,
|
||||
};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||
|
||||
|
@ -409,9 +409,9 @@ impl From<ExprBoolOp> for ParenthesizedExpr {
|
|||
Expr::BoolOp(payload).into()
|
||||
}
|
||||
}
|
||||
impl From<ExprNamedExpr> for ParenthesizedExpr {
|
||||
fn from(payload: ExprNamedExpr) -> Self {
|
||||
Expr::NamedExpr(payload).into()
|
||||
impl From<ExprNamed> for ParenthesizedExpr {
|
||||
fn from(payload: ExprNamed) -> Self {
|
||||
Expr::Named(payload).into()
|
||||
}
|
||||
}
|
||||
impl From<ExprBinOp> for ParenthesizedExpr {
|
||||
|
@ -429,9 +429,9 @@ impl From<ExprLambda> for ParenthesizedExpr {
|
|||
Expr::Lambda(payload).into()
|
||||
}
|
||||
}
|
||||
impl From<ExprIfExp> for ParenthesizedExpr {
|
||||
fn from(payload: ExprIfExp) -> Self {
|
||||
Expr::IfExp(payload).into()
|
||||
impl From<ExprIf> for ParenthesizedExpr {
|
||||
fn from(payload: ExprIf) -> Self {
|
||||
Expr::If(payload).into()
|
||||
}
|
||||
}
|
||||
impl From<ExprDict> for ParenthesizedExpr {
|
||||
|
@ -459,9 +459,9 @@ impl From<ExprDictComp> for ParenthesizedExpr {
|
|||
Expr::DictComp(payload).into()
|
||||
}
|
||||
}
|
||||
impl From<ExprGeneratorExp> for ParenthesizedExpr {
|
||||
fn from(payload: ExprGeneratorExp) -> Self {
|
||||
Expr::GeneratorExp(payload).into()
|
||||
impl From<ExprGenerator> for ParenthesizedExpr {
|
||||
fn from(payload: ExprGenerator) -> Self {
|
||||
Expr::Generator(payload).into()
|
||||
}
|
||||
}
|
||||
impl From<ExprAwait> for ParenthesizedExpr {
|
||||
|
|
|
@ -1028,7 +1028,7 @@ WithItems: Vec<ast::WithItem> = {
|
|||
// ```
|
||||
// In this case, the `(` and `)` are part of the `with` statement.
|
||||
// The same applies to `yield` and `yield from`.
|
||||
let item = if item.optional_vars.is_none() && matches!(item.context_expr, ast::Expr::NamedExpr(_) | ast::Expr::Yield(_) | ast::Expr::YieldFrom(_)) {
|
||||
let item = if item.optional_vars.is_none() && matches!(item.context_expr, ast::Expr::Named(_) | ast::Expr::Yield(_) | ast::Expr::YieldFrom(_)) {
|
||||
ast::WithItem {
|
||||
range: item.range().add_start(TextSize::new(1)).sub_end(TextSize::new(1)),
|
||||
context_expr: item.context_expr,
|
||||
|
@ -1330,7 +1330,7 @@ YieldExpr: crate::parser::ParenthesizedExpr = {
|
|||
};
|
||||
|
||||
Test<Goal>: crate::parser::ParenthesizedExpr = {
|
||||
<location:@L> <body:OrTest<"all">> "if" <test:OrTest<"all">> "else" <orelse:Test<"all">> <end_location:@R> => ast::ExprIfExp {
|
||||
<location:@L> <body:OrTest<"all">> "if" <test:OrTest<"all">> "else" <orelse:Test<"all">> <end_location:@R> => ast::ExprIf {
|
||||
test: Box::new(test.into()),
|
||||
body: Box::new(body.into()),
|
||||
orelse: Box::new(orelse.into()),
|
||||
|
@ -1355,7 +1355,7 @@ NamedExpressionName: crate::parser::ParenthesizedExpr = {
|
|||
|
||||
NamedExpression: crate::parser::ParenthesizedExpr = {
|
||||
<location:@L> <target:NamedExpressionName> ":=" <value:Test<"all">> <end_location:@R> => {
|
||||
ast::ExprNamedExpr {
|
||||
ast::ExprNamed {
|
||||
target: Box::new(target.into()),
|
||||
value: Box::new(value.into()),
|
||||
range: (location..end_location).into(),
|
||||
|
@ -1770,7 +1770,7 @@ Atom<Goal>: crate::parser::ParenthesizedExpr = {
|
|||
expr: e.into(),
|
||||
range: (location..end_location).into(),
|
||||
},
|
||||
<location:@L> "(" <elt:NamedExpressionTest> <generators:CompFor> ")" <end_location:@R> => ast::ExprGeneratorExp {
|
||||
<location:@L> "(" <elt:NamedExpressionTest> <generators:CompFor> ")" <end_location:@R> => ast::ExprGenerator {
|
||||
elt: Box::new(elt.into()),
|
||||
generators,
|
||||
range: (location..end_location).into(),
|
||||
|
@ -1921,8 +1921,8 @@ Arguments: ast::Arguments = {
|
|||
FunctionArgument: (Option<(TextSize, TextSize, Option<ast::Identifier>)>, ast::Expr) = {
|
||||
<location:@L> <elt:NamedExpressionTest> <generators:CompFor?> <end_location:@R> => {
|
||||
let expr = match generators {
|
||||
Some(generators) => ast::Expr::GeneratorExp(
|
||||
ast::ExprGeneratorExp {
|
||||
Some(generators) => ast::Expr::Generator(
|
||||
ast::ExprGenerator {
|
||||
elt: Box::new(elt.into()),
|
||||
generators,
|
||||
range: (location..end_location).into(),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// auto-generated: "lalrpop 0.20.0"
|
||||
// sha3: d64ca7ff27121baee9d7a1b4d0f341932391a365fe75f115987b05bf2aaf538e
|
||||
// sha3: 7adb931f958c3646393245e0bbd0700fd671ccfdea81f378daa8816c9036ca75
|
||||
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
|
||||
use ruff_python_ast::{self as ast, Int, IpyEscapeKind};
|
||||
use crate::{
|
||||
|
@ -35409,7 +35409,7 @@ fn __action159<
|
|||
// ```
|
||||
// In this case, the `(` and `)` are part of the `with` statement.
|
||||
// The same applies to `yield` and `yield from`.
|
||||
let item = if item.optional_vars.is_none() && matches!(item.context_expr, ast::Expr::NamedExpr(_) | ast::Expr::Yield(_) | ast::Expr::YieldFrom(_)) {
|
||||
let item = if item.optional_vars.is_none() && matches!(item.context_expr, ast::Expr::Named(_) | ast::Expr::Yield(_) | ast::Expr::YieldFrom(_)) {
|
||||
ast::WithItem {
|
||||
range: item.range().add_start(TextSize::new(1)).sub_end(TextSize::new(1)),
|
||||
context_expr: item.context_expr,
|
||||
|
@ -35892,7 +35892,7 @@ fn __action183<
|
|||
) -> crate::parser::ParenthesizedExpr
|
||||
{
|
||||
{
|
||||
ast::ExprNamedExpr {
|
||||
ast::ExprNamed {
|
||||
target: Box::new(target.into()),
|
||||
value: Box::new(value.into()),
|
||||
range: (location..end_location).into(),
|
||||
|
@ -36796,8 +36796,8 @@ fn __action242<
|
|||
{
|
||||
{
|
||||
let expr = match generators {
|
||||
Some(generators) => ast::Expr::GeneratorExp(
|
||||
ast::ExprGeneratorExp {
|
||||
Some(generators) => ast::Expr::Generator(
|
||||
ast::ExprGenerator {
|
||||
elt: Box::new(elt.into()),
|
||||
generators,
|
||||
range: (location..end_location).into(),
|
||||
|
@ -39128,7 +39128,7 @@ fn __action403<
|
|||
(_, end_location, _): (TextSize, TextSize, TextSize),
|
||||
) -> crate::parser::ParenthesizedExpr
|
||||
{
|
||||
ast::ExprIfExp {
|
||||
ast::ExprIf {
|
||||
test: Box::new(test.into()),
|
||||
body: Box::new(body.into()),
|
||||
orelse: Box::new(orelse.into()),
|
||||
|
@ -39545,7 +39545,7 @@ fn __action435<
|
|||
(_, end_location, _): (TextSize, TextSize, TextSize),
|
||||
) -> crate::parser::ParenthesizedExpr
|
||||
{
|
||||
ast::ExprIfExp {
|
||||
ast::ExprIf {
|
||||
test: Box::new(test.into()),
|
||||
body: Box::new(body.into()),
|
||||
orelse: Box::new(orelse.into()),
|
||||
|
@ -41410,7 +41410,7 @@ fn __action557<
|
|||
(_, end_location, _): (TextSize, TextSize, TextSize),
|
||||
) -> crate::parser::ParenthesizedExpr
|
||||
{
|
||||
ast::ExprGeneratorExp {
|
||||
ast::ExprGenerator {
|
||||
elt: Box::new(elt.into()),
|
||||
generators,
|
||||
range: (location..end_location).into(),
|
||||
|
@ -42115,7 +42115,7 @@ fn __action599<
|
|||
(_, end_location, _): (TextSize, TextSize, TextSize),
|
||||
) -> crate::parser::ParenthesizedExpr
|
||||
{
|
||||
ast::ExprGeneratorExp {
|
||||
ast::ExprGenerator {
|
||||
elt: Box::new(elt.into()),
|
||||
generators,
|
||||
range: (location..end_location).into(),
|
||||
|
|
|
@ -6,8 +6,8 @@ expression: parse_ast
|
|||
If(
|
||||
StmtIf {
|
||||
range: 0..14,
|
||||
test: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
test: Named(
|
||||
ExprNamed {
|
||||
range: 3..8,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -7,8 +7,8 @@ Ok(
|
|||
Expr(
|
||||
StmtExpr {
|
||||
range: 0..8,
|
||||
value: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
value: Named(
|
||||
ExprNamed {
|
||||
range: 1..7,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -32,8 +32,8 @@ Call(
|
|||
arguments: Arguments {
|
||||
range: 8..141,
|
||||
args: [
|
||||
GeneratorExp(
|
||||
ExprGeneratorExp {
|
||||
Generator(
|
||||
ExprGenerator {
|
||||
range: 14..139,
|
||||
elt: Name(
|
||||
ExprName {
|
||||
|
@ -56,8 +56,8 @@ Call(
|
|||
ExprTuple {
|
||||
range: 33..139,
|
||||
elts: [
|
||||
IfExp(
|
||||
ExprIfExp {
|
||||
If(
|
||||
ExprIf {
|
||||
range: 43..80,
|
||||
test: Name(
|
||||
ExprName {
|
||||
|
@ -100,8 +100,8 @@ Call(
|
|||
),
|
||||
},
|
||||
),
|
||||
IfExp(
|
||||
ExprIfExp {
|
||||
If(
|
||||
ExprIf {
|
||||
range: 90..132,
|
||||
test: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -623,8 +623,8 @@ expression: parse_suite(source).unwrap()
|
|||
If(
|
||||
StmtIf {
|
||||
range: 508..527,
|
||||
test: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
test: Named(
|
||||
ExprNamed {
|
||||
range: 511..521,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
source: crates/ruff_python_parser/src/parser.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
NamedExpr(
|
||||
ExprNamedExpr {
|
||||
Named(
|
||||
ExprNamed {
|
||||
range: 1..15,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -311,8 +311,8 @@ expression: parse_suite(source).unwrap()
|
|||
items: [
|
||||
WithItem {
|
||||
range: 164..170,
|
||||
context_expr: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
context_expr: Named(
|
||||
ExprNamed {
|
||||
range: 164..170,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
@ -350,8 +350,8 @@ expression: parse_suite(source).unwrap()
|
|||
items: [
|
||||
WithItem {
|
||||
range: 183..196,
|
||||
context_expr: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
context_expr: Named(
|
||||
ExprNamed {
|
||||
range: 184..190,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
@ -423,8 +423,8 @@ expression: parse_suite(source).unwrap()
|
|||
items: [
|
||||
WithItem {
|
||||
range: 226..234,
|
||||
context_expr: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
context_expr: Named(
|
||||
ExprNamed {
|
||||
range: 227..233,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
@ -481,8 +481,8 @@ expression: parse_suite(source).unwrap()
|
|||
},
|
||||
WithItem {
|
||||
range: 256..264,
|
||||
context_expr: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
context_expr: Named(
|
||||
ExprNamed {
|
||||
range: 257..263,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
@ -531,8 +531,8 @@ expression: parse_suite(source).unwrap()
|
|||
},
|
||||
WithItem {
|
||||
range: 281..289,
|
||||
context_expr: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
context_expr: Named(
|
||||
ExprNamed {
|
||||
range: 282..288,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
source: crates/ruff_python_parser/src/parser.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
GeneratorExp(
|
||||
ExprGeneratorExp {
|
||||
Generator(
|
||||
ExprGenerator {
|
||||
range: 0..14,
|
||||
elt: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
source: crates/ruff_python_parser/src/parser.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
GeneratorExp(
|
||||
ExprGeneratorExp {
|
||||
Generator(
|
||||
ExprGenerator {
|
||||
range: 0..26,
|
||||
elt: IfExp(
|
||||
ExprIfExp {
|
||||
elt: If(
|
||||
ExprIf {
|
||||
range: 1..14,
|
||||
test: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
source: crates/ruff_python_parser/src/parser.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
GeneratorExp(
|
||||
ExprGeneratorExp {
|
||||
Generator(
|
||||
ExprGenerator {
|
||||
range: 0..23,
|
||||
elt: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
elt: Named(
|
||||
ExprNamed {
|
||||
range: 1..11,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -1846,8 +1846,8 @@ expression: parse_ast
|
|||
},
|
||||
),
|
||||
guard: Some(
|
||||
NamedExpr(
|
||||
ExprNamedExpr {
|
||||
Named(
|
||||
ExprNamed {
|
||||
range: 1472..1482,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
@ -3620,8 +3620,8 @@ expression: parse_ast
|
|||
ExprTuple {
|
||||
range: 2789..2796,
|
||||
elts: [
|
||||
NamedExpr(
|
||||
ExprNamedExpr {
|
||||
Named(
|
||||
ExprNamed {
|
||||
range: 2789..2795,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -623,8 +623,8 @@ expression: parse_suite(source).unwrap()
|
|||
If(
|
||||
StmtIf {
|
||||
range: 481..499,
|
||||
test: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
test: Named(
|
||||
ExprNamed {
|
||||
range: 484..493,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
|
|
@ -166,8 +166,8 @@ expression: parse_suite(source).unwrap()
|
|||
items: [
|
||||
WithItem {
|
||||
range: 78..91,
|
||||
context_expr: IfExp(
|
||||
ExprIfExp {
|
||||
context_expr: If(
|
||||
ExprIf {
|
||||
range: 78..91,
|
||||
test: NumberLiteral(
|
||||
ExprNumberLiteral {
|
||||
|
@ -214,8 +214,8 @@ expression: parse_suite(source).unwrap()
|
|||
items: [
|
||||
WithItem {
|
||||
range: 103..121,
|
||||
context_expr: IfExp(
|
||||
ExprIfExp {
|
||||
context_expr: If(
|
||||
ExprIf {
|
||||
range: 103..116,
|
||||
test: NumberLiteral(
|
||||
ExprNumberLiteral {
|
||||
|
@ -752,8 +752,8 @@ expression: parse_suite(source).unwrap()
|
|||
items: [
|
||||
WithItem {
|
||||
range: 362..368,
|
||||
context_expr: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
context_expr: Named(
|
||||
ExprNamed {
|
||||
range: 362..368,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
@ -791,8 +791,8 @@ expression: parse_suite(source).unwrap()
|
|||
items: [
|
||||
WithItem {
|
||||
range: 381..394,
|
||||
context_expr: NamedExpr(
|
||||
ExprNamedExpr {
|
||||
context_expr: Named(
|
||||
ExprNamed {
|
||||
range: 382..388,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
@ -842,8 +842,8 @@ expression: parse_suite(source).unwrap()
|
|||
ExprTuple {
|
||||
range: 406..422,
|
||||
elts: [
|
||||
NamedExpr(
|
||||
ExprNamedExpr {
|
||||
Named(
|
||||
ExprNamed {
|
||||
range: 407..413,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
@ -862,8 +862,8 @@ expression: parse_suite(source).unwrap()
|
|||
),
|
||||
},
|
||||
),
|
||||
NamedExpr(
|
||||
ExprNamedExpr {
|
||||
Named(
|
||||
ExprNamed {
|
||||
range: 415..421,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
@ -910,8 +910,8 @@ expression: parse_suite(source).unwrap()
|
|||
ExprTuple {
|
||||
range: 434..450,
|
||||
elts: [
|
||||
NamedExpr(
|
||||
ExprNamedExpr {
|
||||
Named(
|
||||
ExprNamed {
|
||||
range: 435..441,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
@ -930,8 +930,8 @@ expression: parse_suite(source).unwrap()
|
|||
),
|
||||
},
|
||||
),
|
||||
NamedExpr(
|
||||
ExprNamedExpr {
|
||||
Named(
|
||||
ExprNamed {
|
||||
range: 443..449,
|
||||
target: Name(
|
||||
ExprName {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue