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

@ -227,14 +227,14 @@ fn handle_enclosed_comment<'a>(
handle_pattern_keyword_comment(comment, pattern_keyword, locator)
}
AnyNodeRef::ExprUnaryOp(unary_op) => handle_unary_op_comment(comment, unary_op, locator),
AnyNodeRef::ExprNamedExpr(_) => handle_named_expr_comment(comment, locator),
AnyNodeRef::ExprNamed(_) => handle_named_expr_comment(comment, locator),
AnyNodeRef::ExprLambda(lambda) => handle_lambda_comment(comment, lambda, locator),
AnyNodeRef::ExprDict(_) => handle_dict_unpacking_comment(comment, locator)
.or_else(|comment| handle_bracketed_end_of_line_comment(comment, locator))
.or_else(|comment| handle_key_value_comment(comment, locator)),
AnyNodeRef::ExprDictComp(_) => handle_key_value_comment(comment, locator)
.or_else(|comment| handle_bracketed_end_of_line_comment(comment, locator)),
AnyNodeRef::ExprIfExp(expr_if) => handle_expr_if_comment(comment, expr_if, locator),
AnyNodeRef::ExprIf(expr_if) => handle_expr_if_comment(comment, expr_if, locator),
AnyNodeRef::ExprSlice(expr_slice) => {
handle_slice_comments(comment, expr_slice, comment_ranges, locator)
}
@ -317,7 +317,7 @@ fn handle_enclosed_comment<'a>(
parenthesized: true,
..
}) => handle_bracketed_end_of_line_comment(comment, locator),
AnyNodeRef::ExprGeneratorExp(generator) if generator.parenthesized => {
AnyNodeRef::ExprGenerator(generator) if generator.parenthesized => {
handle_bracketed_end_of_line_comment(comment, locator)
}
_ => CommentPlacement::Default(comment),
@ -1353,10 +1353,10 @@ fn handle_attribute_comment<'a>(
/// happens if the comments are in a weird position but it also doesn't hurt handling it.
fn handle_expr_if_comment<'a>(
comment: DecoratedComment<'a>,
expr_if: &'a ast::ExprIfExp,
expr_if: &'a ast::ExprIf,
locator: &Locator,
) -> CommentPlacement<'a> {
let ast::ExprIfExp {
let ast::ExprIf {
range: _,
test,
body,
@ -1612,7 +1612,7 @@ fn handle_named_expr_comment<'a>(
comment: DecoratedComment<'a>,
locator: &Locator,
) -> CommentPlacement<'a> {
debug_assert!(comment.enclosing_node().is_expr_named_expr());
debug_assert!(comment.enclosing_node().is_expr_named());
let (Some(target), Some(value)) = (comment.preceding_node(), comment.following_node()) else {
return CommentPlacement::Default(comment);

View file

@ -1,6 +1,6 @@
use ruff_formatter::{format_args, write, FormatRuleWithOptions};
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprGeneratorExp;
use ruff_python_ast::ExprGenerator;
use crate::comments::SourceComment;
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
@ -20,7 +20,7 @@ pub enum GeneratorExpParentheses {
Preserve,
}
impl FormatRuleWithOptions<ExprGeneratorExp, PyFormatContext<'_>> for FormatExprGeneratorExp {
impl FormatRuleWithOptions<ExprGenerator, PyFormatContext<'_>> for FormatExprGenerator {
type Options = GeneratorExpParentheses;
fn with_options(mut self, options: Self::Options) -> Self {
@ -30,13 +30,13 @@ impl FormatRuleWithOptions<ExprGeneratorExp, PyFormatContext<'_>> for FormatExpr
}
#[derive(Default)]
pub struct FormatExprGeneratorExp {
pub struct FormatExprGenerator {
parentheses: GeneratorExpParentheses,
}
impl FormatNodeRule<ExprGeneratorExp> for FormatExprGeneratorExp {
fn fmt_fields(&self, item: &ExprGeneratorExp, f: &mut PyFormatter) -> FormatResult<()> {
let ExprGeneratorExp {
impl FormatNodeRule<ExprGenerator> for FormatExprGenerator {
fn fmt_fields(&self, item: &ExprGenerator, f: &mut PyFormatter) -> FormatResult<()> {
let ExprGenerator {
range: _,
elt,
generators,
@ -87,7 +87,7 @@ impl FormatNodeRule<ExprGeneratorExp> for FormatExprGeneratorExp {
}
}
impl NeedsParentheses for ExprGeneratorExp {
impl NeedsParentheses for ExprGenerator {
fn needs_parentheses(
&self,
parent: AnyNodeRef,

View file

@ -1,6 +1,6 @@
use ruff_formatter::{write, FormatRuleWithOptions};
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{Expr, ExprIfExp};
use ruff_python_ast::{Expr, ExprIf};
use crate::comments::leading_comments;
use crate::expression::parentheses::{
@ -10,11 +10,11 @@ use crate::expression::parentheses::{
use crate::prelude::*;
#[derive(Default, Copy, Clone)]
pub enum ExprIfExpLayout {
pub enum ExprIfLayout {
#[default]
Default,
/// The [`ExprIfExp`] is nested inside another [`ExprIfExp`], so it should not be given a new
/// The [`ExprIf`] is nested inside another [`ExprIf`], so it should not be given a new
/// group. For example, avoid grouping the `else` clause in:
/// ```python
/// clone._iterable_class = (
@ -29,12 +29,12 @@ pub enum ExprIfExpLayout {
}
#[derive(Default)]
pub struct FormatExprIfExp {
layout: ExprIfExpLayout,
pub struct FormatExprIf {
layout: ExprIfLayout,
}
impl FormatRuleWithOptions<ExprIfExp, PyFormatContext<'_>> for FormatExprIfExp {
type Options = ExprIfExpLayout;
impl FormatRuleWithOptions<ExprIf, PyFormatContext<'_>> for FormatExprIf {
type Options = ExprIfLayout;
fn with_options(mut self, options: Self::Options) -> Self {
self.layout = options;
@ -42,9 +42,9 @@ impl FormatRuleWithOptions<ExprIfExp, PyFormatContext<'_>> for FormatExprIfExp {
}
}
impl FormatNodeRule<ExprIfExp> for FormatExprIfExp {
fn fmt_fields(&self, item: &ExprIfExp, f: &mut PyFormatter) -> FormatResult<()> {
let ExprIfExp {
impl FormatNodeRule<ExprIf> for FormatExprIf {
fn fmt_fields(&self, item: &ExprIf, f: &mut PyFormatter) -> FormatResult<()> {
let ExprIf {
range: _,
test,
body,
@ -76,13 +76,13 @@ impl FormatNodeRule<ExprIfExp> for FormatExprIfExp {
});
match self.layout {
ExprIfExpLayout::Default => in_parentheses_only_group(&inner).fmt(f),
ExprIfExpLayout::Nested => inner.fmt(f),
ExprIfLayout::Default => in_parentheses_only_group(&inner).fmt(f),
ExprIfLayout::Nested => inner.fmt(f),
}
}
}
impl NeedsParentheses for ExprIfExp {
impl NeedsParentheses for ExprIf {
fn needs_parentheses(
&self,
parent: AnyNodeRef,
@ -104,14 +104,14 @@ struct FormatOrElse<'a> {
impl Format<PyFormatContext<'_>> for FormatOrElse<'_> {
fn fmt(&self, f: &mut Formatter<PyFormatContext<'_>>) -> FormatResult<()> {
match self.orelse {
Expr::IfExp(expr)
Expr::If(expr)
if !is_expression_parenthesized(
expr.into(),
f.context().comments().ranges(),
f.context().source(),
) =>
{
write!(f, [expr.format().with_options(ExprIfExpLayout::Nested)])
write!(f, [expr.format().with_options(ExprIfLayout::Nested)])
}
_ => write!(f, [in_parentheses_only_group(&self.orelse.format())]),
}

View file

@ -1,6 +1,6 @@
use ruff_formatter::{format_args, write};
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprNamedExpr;
use ruff_python_ast::ExprNamed;
use crate::comments::{dangling_comments, SourceComment};
use crate::expression::parentheses::{
@ -9,11 +9,11 @@ use crate::expression::parentheses::{
use crate::prelude::*;
#[derive(Default)]
pub struct FormatExprNamedExpr;
pub struct FormatExprNamed;
impl FormatNodeRule<ExprNamedExpr> for FormatExprNamedExpr {
fn fmt_fields(&self, item: &ExprNamedExpr, f: &mut PyFormatter) -> FormatResult<()> {
let ExprNamedExpr {
impl FormatNodeRule<ExprNamed> for FormatExprNamed {
fn fmt_fields(&self, item: &ExprNamed, f: &mut PyFormatter) -> FormatResult<()> {
let ExprNamed {
target,
value,
range: _,
@ -53,7 +53,7 @@ impl FormatNodeRule<ExprNamedExpr> for FormatExprNamedExpr {
}
}
impl NeedsParentheses for ExprNamedExpr {
impl NeedsParentheses for ExprNamed {
fn needs_parentheses(
&self,
parent: AnyNodeRef,

View file

@ -34,14 +34,14 @@ pub(crate) mod expr_dict;
pub(crate) mod expr_dict_comp;
pub(crate) mod expr_ellipsis_literal;
pub(crate) mod expr_f_string;
pub(crate) mod expr_generator_exp;
pub(crate) mod expr_if_exp;
pub(crate) mod expr_generator;
pub(crate) mod expr_if;
pub(crate) mod expr_ipy_escape_command;
pub(crate) mod expr_lambda;
pub(crate) mod expr_list;
pub(crate) mod expr_list_comp;
pub(crate) mod expr_name;
pub(crate) mod expr_named_expr;
pub(crate) mod expr_named;
pub(crate) mod expr_none_literal;
pub(crate) mod expr_number_literal;
pub(crate) mod expr_set;
@ -77,17 +77,17 @@ impl FormatRule<Expr, PyFormatContext<'_>> for FormatExpr {
let format_expr = format_with(|f| match expression {
Expr::BoolOp(expr) => expr.format().fmt(f),
Expr::NamedExpr(expr) => expr.format().fmt(f),
Expr::Named(expr) => expr.format().fmt(f),
Expr::BinOp(expr) => expr.format().fmt(f),
Expr::UnaryOp(expr) => expr.format().fmt(f),
Expr::Lambda(expr) => expr.format().fmt(f),
Expr::IfExp(expr) => expr.format().fmt(f),
Expr::If(expr) => expr.format().fmt(f),
Expr::Dict(expr) => expr.format().fmt(f),
Expr::Set(expr) => expr.format().fmt(f),
Expr::ListComp(expr) => expr.format().fmt(f),
Expr::SetComp(expr) => expr.format().fmt(f),
Expr::DictComp(expr) => expr.format().fmt(f),
Expr::GeneratorExp(expr) => expr.format().fmt(f),
Expr::Generator(expr) => expr.format().fmt(f),
Expr::Await(expr) => expr.format().fmt(f),
Expr::Yield(expr) => expr.format().fmt(f),
Expr::YieldFrom(expr) => expr.format().fmt(f),
@ -265,17 +265,17 @@ fn format_with_parentheses_comments(
let fmt_fields = format_with(|f| match expression {
Expr::BoolOp(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::NamedExpr(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::Named(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::BinOp(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::UnaryOp(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::Lambda(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::IfExp(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::If(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::Dict(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::Set(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::ListComp(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::SetComp(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::DictComp(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::GeneratorExp(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::Generator(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::Await(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::Yield(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
Expr::YieldFrom(expr) => FormatNodeRule::fmt_fields(expr.format().rule(), expr, f),
@ -461,17 +461,17 @@ impl NeedsParentheses for Expr {
) -> OptionalParentheses {
match self {
Expr::BoolOp(expr) => expr.needs_parentheses(parent, context),
Expr::NamedExpr(expr) => expr.needs_parentheses(parent, context),
Expr::Named(expr) => expr.needs_parentheses(parent, context),
Expr::BinOp(expr) => expr.needs_parentheses(parent, context),
Expr::UnaryOp(expr) => expr.needs_parentheses(parent, context),
Expr::Lambda(expr) => expr.needs_parentheses(parent, context),
Expr::IfExp(expr) => expr.needs_parentheses(parent, context),
Expr::If(expr) => expr.needs_parentheses(parent, context),
Expr::Dict(expr) => expr.needs_parentheses(parent, context),
Expr::Set(expr) => expr.needs_parentheses(parent, context),
Expr::ListComp(expr) => expr.needs_parentheses(parent, context),
Expr::SetComp(expr) => expr.needs_parentheses(parent, context),
Expr::DictComp(expr) => expr.needs_parentheses(parent, context),
Expr::GeneratorExp(expr) => expr.needs_parentheses(parent, context),
Expr::Generator(expr) => expr.needs_parentheses(parent, context),
Expr::Await(expr) => expr.needs_parentheses(parent, context),
Expr::Yield(expr) => expr.needs_parentheses(parent, context),
Expr::YieldFrom(expr) => expr.needs_parentheses(parent, context),
@ -669,7 +669,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> {
return;
}
Expr::GeneratorExp(generator) if generator.parenthesized => {
Expr::Generator(generator) if generator.parenthesized => {
self.any_parenthesized_expressions = true;
// The values are always parenthesized, don't visit.
return;
@ -693,7 +693,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> {
range: _,
}) => self.update_max_precedence(OperatorPrecedence::from(*op)),
Expr::IfExp(_) => {
Expr::If(_) => {
// + 1 for the if and one for the else
self.update_max_precedence_with_count(OperatorPrecedence::Conditional, 2);
}
@ -763,7 +763,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> {
}
// Non terminal nodes that don't have a termination token.
Expr::NamedExpr(_) | Expr::GeneratorExp(_) | Expr::Tuple(_) => {}
Expr::Named(_) | Expr::Generator(_) | Expr::Tuple(_) => {}
// Expressions with sub expressions but a preceding token
// Mark this expression as first expression and not the sub expression.
@ -1035,7 +1035,7 @@ pub(crate) fn has_own_parentheses(
Some(OwnParentheses::NonEmpty)
}
Expr::GeneratorExp(generator) if generator.parenthesized => Some(OwnParentheses::NonEmpty),
Expr::Generator(generator) if generator.parenthesized => Some(OwnParentheses::NonEmpty),
// These expressions must contain _some_ child or trivia token in order to be non-empty.
Expr::List(ast::ExprList { elts, .. }) | Expr::Set(ast::ExprSet { elts, .. }) => {
@ -1118,12 +1118,12 @@ pub(crate) fn is_expression_huggable(expr: &Expr, context: &PyFormatContext) ->
Expr::Starred(ast::ExprStarred { value, .. }) => is_expression_huggable(value, context),
Expr::BoolOp(_)
| Expr::NamedExpr(_)
| Expr::Named(_)
| Expr::BinOp(_)
| Expr::UnaryOp(_)
| Expr::Lambda(_)
| Expr::IfExp(_)
| Expr::GeneratorExp(_)
| Expr::If(_)
| Expr::Generator(_)
| Expr::Await(_)
| Expr::Yield(_)
| Expr::YieldFrom(_)
@ -1193,7 +1193,7 @@ impl From<Operator> for OperatorPrecedence {
pub(crate) fn is_splittable_expression(expr: &Expr, context: &PyFormatContext) -> bool {
match expr {
// Single token expressions. They never have any split points.
Expr::NamedExpr(_)
Expr::Named(_)
| Expr::Name(_)
| Expr::NumberLiteral(_)
| Expr::BooleanLiteral(_)
@ -1206,8 +1206,8 @@ pub(crate) fn is_splittable_expression(expr: &Expr, context: &PyFormatContext) -
Expr::Compare(_)
| Expr::BinOp(_)
| Expr::BoolOp(_)
| Expr::IfExp(_)
| Expr::GeneratorExp(_)
| Expr::If(_)
| Expr::Generator(_)
| Expr::Subscript(_)
| Expr::Await(_)
| Expr::ListComp(_)

View file

@ -966,38 +966,38 @@ impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprBoolOp {
}
}
impl FormatRule<ast::ExprNamedExpr, PyFormatContext<'_>>
for crate::expression::expr_named_expr::FormatExprNamedExpr
impl FormatRule<ast::ExprNamed, PyFormatContext<'_>>
for crate::expression::expr_named::FormatExprNamed
{
#[inline]
fn fmt(&self, node: &ast::ExprNamedExpr, f: &mut PyFormatter) -> FormatResult<()> {
FormatNodeRule::<ast::ExprNamedExpr>::fmt(self, node, f)
fn fmt(&self, node: &ast::ExprNamed, f: &mut PyFormatter) -> FormatResult<()> {
FormatNodeRule::<ast::ExprNamed>::fmt(self, node, f)
}
}
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::ExprNamedExpr {
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::ExprNamed {
type Format<'a> = FormatRefWithRule<
'a,
ast::ExprNamedExpr,
crate::expression::expr_named_expr::FormatExprNamedExpr,
ast::ExprNamed,
crate::expression::expr_named::FormatExprNamed,
PyFormatContext<'ast>,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::expression::expr_named_expr::FormatExprNamedExpr::default(),
crate::expression::expr_named::FormatExprNamed::default(),
)
}
}
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprNamedExpr {
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprNamed {
type Format = FormatOwnedWithRule<
ast::ExprNamedExpr,
crate::expression::expr_named_expr::FormatExprNamedExpr,
ast::ExprNamed,
crate::expression::expr_named::FormatExprNamed,
PyFormatContext<'ast>,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::expression::expr_named_expr::FormatExprNamedExpr::default(),
crate::expression::expr_named::FormatExprNamed::default(),
)
}
}
@ -1110,39 +1110,31 @@ impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprLambda {
}
}
impl FormatRule<ast::ExprIfExp, PyFormatContext<'_>>
for crate::expression::expr_if_exp::FormatExprIfExp
{
impl FormatRule<ast::ExprIf, PyFormatContext<'_>> for crate::expression::expr_if::FormatExprIf {
#[inline]
fn fmt(&self, node: &ast::ExprIfExp, f: &mut PyFormatter) -> FormatResult<()> {
FormatNodeRule::<ast::ExprIfExp>::fmt(self, node, f)
fn fmt(&self, node: &ast::ExprIf, f: &mut PyFormatter) -> FormatResult<()> {
FormatNodeRule::<ast::ExprIf>::fmt(self, node, f)
}
}
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::ExprIfExp {
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::ExprIf {
type Format<'a> = FormatRefWithRule<
'a,
ast::ExprIfExp,
crate::expression::expr_if_exp::FormatExprIfExp,
ast::ExprIf,
crate::expression::expr_if::FormatExprIf,
PyFormatContext<'ast>,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::expression::expr_if_exp::FormatExprIfExp::default(),
)
FormatRefWithRule::new(self, crate::expression::expr_if::FormatExprIf::default())
}
}
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprIfExp {
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprIf {
type Format = FormatOwnedWithRule<
ast::ExprIfExp,
crate::expression::expr_if_exp::FormatExprIfExp,
ast::ExprIf,
crate::expression::expr_if::FormatExprIf,
PyFormatContext<'ast>,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::expression::expr_if_exp::FormatExprIfExp::default(),
)
FormatOwnedWithRule::new(self, crate::expression::expr_if::FormatExprIf::default())
}
}
@ -1318,38 +1310,38 @@ impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprDictComp {
}
}
impl FormatRule<ast::ExprGeneratorExp, PyFormatContext<'_>>
for crate::expression::expr_generator_exp::FormatExprGeneratorExp
impl FormatRule<ast::ExprGenerator, PyFormatContext<'_>>
for crate::expression::expr_generator::FormatExprGenerator
{
#[inline]
fn fmt(&self, node: &ast::ExprGeneratorExp, f: &mut PyFormatter) -> FormatResult<()> {
FormatNodeRule::<ast::ExprGeneratorExp>::fmt(self, node, f)
fn fmt(&self, node: &ast::ExprGenerator, f: &mut PyFormatter) -> FormatResult<()> {
FormatNodeRule::<ast::ExprGenerator>::fmt(self, node, f)
}
}
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::ExprGeneratorExp {
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::ExprGenerator {
type Format<'a> = FormatRefWithRule<
'a,
ast::ExprGeneratorExp,
crate::expression::expr_generator_exp::FormatExprGeneratorExp,
ast::ExprGenerator,
crate::expression::expr_generator::FormatExprGenerator,
PyFormatContext<'ast>,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::expression::expr_generator_exp::FormatExprGeneratorExp::default(),
crate::expression::expr_generator::FormatExprGenerator::default(),
)
}
}
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprGeneratorExp {
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprGenerator {
type Format = FormatOwnedWithRule<
ast::ExprGeneratorExp,
crate::expression::expr_generator_exp::FormatExprGeneratorExp,
ast::ExprGenerator,
crate::expression::expr_generator::FormatExprGenerator,
PyFormatContext<'ast>,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::expression::expr_generator_exp::FormatExprGeneratorExp::default(),
crate::expression::expr_generator::FormatExprGenerator::default(),
)
}
}

View file

@ -4,7 +4,7 @@ use ruff_python_trivia::{PythonWhitespace, SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
use crate::comments::SourceComment;
use crate::expression::expr_generator_exp::GeneratorExpParentheses;
use crate::expression::expr_generator::GeneratorExpParentheses;
use crate::expression::is_expression_huggable;
use crate::expression::parentheses::{empty_parenthesized, parenthesized, Parentheses};
use crate::other::commas;
@ -40,7 +40,7 @@ impl FormatNodeRule<Arguments> for FormatArguments {
match args.as_ref() {
[arg] if keywords.is_empty() => {
match arg {
Expr::GeneratorExp(generator_exp) => joiner.entry(
Expr::Generator(generator_exp) => joiner.entry(
generator_exp,
&generator_exp
.format()

View file

@ -648,17 +648,17 @@ impl Format<PyFormatContext<'_>> for FormatEnclosingNode<'_> {
AnyNodeRef::ElifElseClause(node) => node.format().fmt(f),
AnyNodeRef::ExprBoolOp(_)
| AnyNodeRef::ExprNamedExpr(_)
| AnyNodeRef::ExprNamed(_)
| AnyNodeRef::ExprBinOp(_)
| AnyNodeRef::ExprUnaryOp(_)
| AnyNodeRef::ExprLambda(_)
| AnyNodeRef::ExprIfExp(_)
| AnyNodeRef::ExprIf(_)
| AnyNodeRef::ExprDict(_)
| AnyNodeRef::ExprSet(_)
| AnyNodeRef::ExprListComp(_)
| AnyNodeRef::ExprSetComp(_)
| AnyNodeRef::ExprDictComp(_)
| AnyNodeRef::ExprGeneratorExp(_)
| AnyNodeRef::ExprGenerator(_)
| AnyNodeRef::ExprAwait(_)
| AnyNodeRef::ExprYield(_)
| AnyNodeRef::ExprYieldFrom(_)