mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 17:10:34 +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
|
@ -76,7 +76,7 @@ impl From<&Expr> for ResolvedPythonType {
|
|||
Expr::List(_) => ResolvedPythonType::Atom(PythonType::List),
|
||||
Expr::ListComp(_) => ResolvedPythonType::Atom(PythonType::List),
|
||||
Expr::Tuple(_) => ResolvedPythonType::Atom(PythonType::Tuple),
|
||||
Expr::GeneratorExp(_) => ResolvedPythonType::Atom(PythonType::Generator),
|
||||
Expr::Generator(_) => ResolvedPythonType::Atom(PythonType::Generator),
|
||||
Expr::FString(_) => ResolvedPythonType::Atom(PythonType::String),
|
||||
Expr::StringLiteral(_) => ResolvedPythonType::Atom(PythonType::String),
|
||||
Expr::BytesLiteral(_) => ResolvedPythonType::Atom(PythonType::Bytes),
|
||||
|
@ -97,10 +97,8 @@ impl From<&Expr> for ResolvedPythonType {
|
|||
Expr::NoneLiteral(_) => ResolvedPythonType::Atom(PythonType::None),
|
||||
Expr::EllipsisLiteral(_) => ResolvedPythonType::Atom(PythonType::Ellipsis),
|
||||
// Simple container expressions.
|
||||
Expr::NamedExpr(ast::ExprNamedExpr { value, .. }) => {
|
||||
ResolvedPythonType::from(value.as_ref())
|
||||
}
|
||||
Expr::IfExp(ast::ExprIfExp { body, orelse, .. }) => {
|
||||
Expr::Named(ast::ExprNamed { value, .. }) => ResolvedPythonType::from(value.as_ref()),
|
||||
Expr::If(ast::ExprIf { body, orelse, .. }) => {
|
||||
let body = ResolvedPythonType::from(body.as_ref());
|
||||
let orelse = ResolvedPythonType::from(orelse.as_ref());
|
||||
body.union(orelse)
|
||||
|
|
|
@ -466,8 +466,8 @@ fn check_type<T: TypeChecker>(binding: &Binding, semantic: &SemanticModel) -> bo
|
|||
binding.source.is_some_and(|source| {
|
||||
semantic
|
||||
.expressions(source)
|
||||
.find_map(|expr| expr.as_named_expr_expr())
|
||||
.and_then(|ast::ExprNamedExpr { target, value, .. }| {
|
||||
.find_map(|expr| expr.as_named_expr())
|
||||
.and_then(|ast::ExprNamed { target, value, .. }| {
|
||||
match_value(binding, target.as_ref(), value.as_ref())
|
||||
})
|
||||
.is_some_and(|value| T::match_initializer(value, semantic))
|
||||
|
@ -818,8 +818,8 @@ pub fn find_binding_value<'a>(binding: &Binding, semantic: &'a SemanticModel) ->
|
|||
let parent_id = binding.source?;
|
||||
let parent = semantic
|
||||
.expressions(parent_id)
|
||||
.find_map(|expr| expr.as_named_expr_expr());
|
||||
if let Some(ast::ExprNamedExpr { target, value, .. }) = parent {
|
||||
.find_map(|expr| expr.as_named_expr());
|
||||
if let Some(ast::ExprNamed { target, value, .. }) = parent {
|
||||
return match_value(binding, target.as_ref(), value.as_ref());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue