From cd91a92b63073e22805948f4adcf52c908c11e0c Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 26 Feb 2024 14:34:46 +0100 Subject: [PATCH] Add `parenthesized` to `ExprGenerator` --- .../src/checkers/ast/analyze/expression.rs | 3 +- crates/ruff_linter/src/checkers/ast/mod.rs | 3 +- .../rules/duplicate_exceptions.rs | 2 +- .../rules/multiple_starts_ends_with.rs | 2 +- .../rules/unnecessary_literal_union.rs | 6 +-- .../rules/unnecessary_type_union.rs | 4 +- .../flake8_pytest_style/rules/parametrize.rs | 4 +- .../flake8_simplify/rules/ast_bool_op.rs | 6 +-- .../rules/reimplemented_builtin.rs | 1 + .../rules/pylint/rules/redefined_loop_name.rs | 2 +- .../rules/repeated_equality_comparison.rs | 2 +- .../rules/pyupgrade/rules/os_error_alias.rs | 2 +- .../pyupgrade/rules/timeout_error_alias.rs | 2 +- .../pyupgrade/rules/use_pep695_type_alias.rs | 2 +- .../src/rules/refurb/rules/repeated_append.rs | 2 +- .../rules/collection_literal_concatenation.rs | 2 +- .../src/rules/ruff/rules/never_union.rs | 4 +- .../src/rules/ruff/rules/sequence_sorting.rs | 3 +- crates/ruff_python_ast/src/comparable.rs | 3 +- crates/ruff_python_ast/src/helpers.rs | 5 ++- crates/ruff_python_ast/src/node.rs | 3 +- crates/ruff_python_ast/src/nodes.rs | 5 ++- crates/ruff_python_ast/src/visitor.rs | 3 +- .../src/visitor/transformer.rs | 3 +- crates/ruff_python_codegen/src/generator.rs | 2 + .../src/comments/placement.rs | 7 +--- .../src/expression/expr_generator_exp.rs | 39 +------------------ .../src/expression/expr_tuple.rs | 2 +- .../src/expression/mod.rs | 15 ++----- crates/ruff_python_parser/src/context.rs | 4 +- crates/ruff_python_parser/src/python.lalrpop | 20 +++++----- crates/ruff_python_parser/src/python.rs | 29 +++++++------- ...ser__context__tests__assign_attribute.snap | 2 +- ...on_parser__context__tests__assign_for.snap | 2 +- ...n_parser__context__tests__assign_list.snap | 2 +- ...ser__context__tests__assign_list_comp.snap | 2 +- ...n_parser__context__tests__assign_name.snap | 2 +- ...rser__context__tests__assign_set_comp.snap | 2 +- ...arser__context__tests__assign_starred.snap | 4 +- ...ser__context__tests__assign_subscript.snap | 2 +- ..._parser__context__tests__assign_tuple.snap | 4 +- ..._context__tests__aug_assign_attribute.snap | 2 +- ..._context__tests__aug_assign_subscript.snap | 2 +- ...thon_parser__invalid__tests__ok_tuple.snap | 4 +- ...ython_parser__parser__tests__fstrings.snap | 4 +- ..._tests__generator_expression_argument.snap | 3 +- ...f_python_parser__parser__tests__match.snap | 6 +-- ...r__parser__tests__match_as_identifier.snap | 12 +++--- ...__tests__parenthesized_with_statement.snap | 4 +- ...ser__tests__parse_class_generic_types.snap | 2 +- ...ests__parse_double_list_comprehension.snap | 2 +- ...ser__tests__parse_function_definition.snap | 2 +- ..._tests__parse_generator_comprehension.snap | 1 + ...parse_if_else_generator_comprehension.snap | 1 + ...ed_expression_generator_comprehension.snap | 1 + ...n_parser__parser__tests__parse_tuples.snap | 4 +- ...parser__tests__parse_type_declaration.snap | 8 ++-- ...f_python_parser__parser__tests__patma.snap | 14 +++---- ...hon_parser__parser__tests__star_index.snap | 8 ++-- ...f_python_parser__parser__tests__tuple.snap | 10 ++--- ...er__parser__tests__type_as_identifier.snap | 12 +++--- ...parser__parser__tests__with_statement.snap | 20 +++++----- 62 files changed, 156 insertions(+), 180 deletions(-) diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index 988ac0442e0038..1e822a4775561b 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -134,7 +134,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { elts, ctx, range: _, - is_parenthesized: _, + parenthesized: _, }) | Expr::List(ast::ExprList { elts, @@ -1452,6 +1452,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { generators, elt: _, range: _, + parenthesized: _, }, ) => { if checker.enabled(Rule::UnnecessaryListIndexLookup) { diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 64b13f344132ec..970f33e2aa08b3 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -1007,6 +1007,7 @@ where elt, generators, range: _, + parenthesized: _, }) => { self.visit_generators(generators); self.visit_expr(elt); @@ -1327,7 +1328,7 @@ where elts, ctx, range: _, - is_parenthesized: _, + parenthesized: _, }) = slice.as_ref() { let mut iter = elts.iter(); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs index 02e4a09393e89b..3f708002e2c7e9 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs @@ -109,7 +109,7 @@ fn type_pattern(elts: Vec<&Expr>) -> Expr { elts: elts.into_iter().cloned().collect(), ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, } .into() } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs index fbd43b4f472a48..ba2dc033cf94e4 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs @@ -173,7 +173,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) { .collect(), ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, }); let node1 = Expr::Name(ast::ExprName { id: arg_name.into(), diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs index 4a9487719c19d0..b3a49d819732c4 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs @@ -72,7 +72,7 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Exp elts, range: _, ctx: _, - is_parenthesized: _, + parenthesized: _, }) = slice.as_ref() { for expr in elts { @@ -124,7 +124,7 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Exp elts: literal_exprs.into_iter().cloned().collect(), range: TextRange::default(), ctx: ExprContext::Load, - is_parenthesized: true, + parenthesized: true, })), range: TextRange::default(), ctx: ExprContext::Load, @@ -150,7 +150,7 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Exp elts, range: TextRange::default(), ctx: ExprContext::Load, - is_parenthesized: true, + parenthesized: true, })), range: TextRange::default(), ctx: ExprContext::Load, diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs index 0452155fa0767b..d4cd2cde2c9a88 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs @@ -130,7 +130,7 @@ pub(crate) fn unnecessary_type_union<'a>(checker: &mut Checker, union: &'a Expr) .collect(), ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, })), ctx: ExprContext::Load, range: TextRange::default(), @@ -152,7 +152,7 @@ pub(crate) fn unnecessary_type_union<'a>(checker: &mut Checker, union: &'a Expr) elts: exprs.into_iter().cloned().collect(), ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, })), ctx: ExprContext::Load, range: TextRange::default(), diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs index b819b9a19b8762..8a575dc9ff52d8 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -337,7 +337,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) { .collect(), ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, }); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( format!("({})", checker.generator().expr(&node)), @@ -445,7 +445,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) { elts: elts.clone(), ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, }); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( format!("({})", checker.generator().expr(&node)), diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs index 6d420aa7f696d2..88a08dd38e6eb2 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -428,7 +428,7 @@ pub(crate) fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) { .collect(), ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, }; let node1 = ast::ExprName { id: "isinstance".into(), @@ -544,7 +544,7 @@ pub(crate) fn compare_with_tuple(checker: &mut Checker, expr: &Expr) { elts: comparators.into_iter().map(Clone::clone).collect(), ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, }; let node1 = ast::ExprName { id: id.into(), @@ -720,7 +720,7 @@ fn get_short_circuit_edit( generator.expr(expr) }; Edit::range_replacement( - if matches!(expr, Expr::Tuple(ast::ExprTuple { elts, ctx: _, range: _, is_parenthesized: _}) if !elts.is_empty()) + if matches!(expr, Expr::Tuple(ast::ExprTuple { elts, ctx: _, range: _, parenthesized: _}) if !elts.is_empty()) { format!("({content})") } else { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs index 09475ad8abd3b1..30273ace9d9cee 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -382,6 +382,7 @@ fn return_stmt(id: &str, test: &Expr, target: &Expr, iter: &Expr, generator: Gen range: TextRange::default(), }], range: TextRange::default(), + parenthesized: false, }; let node1 = ast::ExprName { id: id.into(), diff --git a/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs b/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs index 3d1dc803507e12..dc86eb4dd28f6e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs @@ -305,7 +305,7 @@ fn assignment_targets_from_expr<'a>( ctx: ExprContext::Store, elts, range: _, - is_parenthesized: _, + parenthesized: _, }) => Box::new( elts.iter() .flat_map(|elt| assignment_targets_from_expr(elt, dummy_variable_rgx)), diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs index a784e274020e47..df3ab969240c71 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs @@ -145,7 +145,7 @@ pub(crate) fn repeated_equality_comparison(checker: &mut Checker, bool_op: &ast: elts: comparators.iter().copied().cloned().collect(), range: TextRange::default(), ctx: ExprContext::Load, - is_parenthesized: true, + parenthesized: true, })]), range: bool_op.range(), })), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs index 71fef6600657f6..dca5dfe715f3df 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs @@ -127,7 +127,7 @@ fn tuple_diagnostic(checker: &mut Checker, tuple: &ast::ExprTuple, aliases: &[&E elts: remaining, ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, }; format!("({})", checker.generator().expr(&node.into())) }; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs index 64d4c9f2c88736..43ffafa3d5df23 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs @@ -141,7 +141,7 @@ fn tuple_diagnostic(checker: &mut Checker, tuple: &ast::ExprTuple, aliases: &[&E elts: remaining, ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, }; format!("({})", checker.generator().expr(&node.into())) }; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs index 1447266228385b..1966ce1b350558 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs @@ -127,7 +127,7 @@ pub(crate) fn non_pep695_type_alias(checker: &mut Checker, stmt: &StmtAnnAssign) range: TextRange::default(), elts: constraints.into_iter().cloned().collect(), ctx: ast::ExprContext::Load, - is_parenthesized: true, + parenthesized: true, }))) } None => None, diff --git a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs index c3a735ca7bc896..1eb6bbaf6ff2db 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs @@ -347,7 +347,7 @@ fn make_suggestion(group: &AppendGroup, generator: Generator) -> String { elts, ctx: ast::ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, }; // Make `var.extend`. // NOTE: receiver is the same for all appends and that's why we can take the first. diff --git a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs index f9a742978e60d3..db8913497535bf 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs @@ -162,7 +162,7 @@ fn concatenate_expressions(expr: &Expr) -> Option<(Expr, Type)> { elts: new_elts, ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, } .into(), }; diff --git a/crates/ruff_linter/src/rules/ruff/rules/never_union.rs b/crates/ruff_linter/src/rules/ruff/rules/never_union.rs index 931bb4e5f94af9..45abda90676417 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/never_union.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/never_union.rs @@ -116,7 +116,7 @@ pub(crate) fn never_union(checker: &mut Checker, expr: &Expr) { elts, ctx: _, range: _, - is_parenthesized: _, + parenthesized: _, }) = slice.as_ref() else { return; @@ -158,7 +158,7 @@ pub(crate) fn never_union(checker: &mut Checker, expr: &Expr) { elts: rest, ctx: ast::ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, })), ctx: ast::ExprContext::Load, range: TextRange::default(), diff --git a/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs b/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs index 0dd8f76d1af7ea..e3bc28e5405628 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs @@ -150,7 +150,8 @@ impl SequenceKind<'_> { Self::List => ("[", "]"), Self::Set => ("{", "}"), Self::Tuple(ast::ExprTuple { - is_parenthesized, .. + parenthesized: is_parenthesized, + .. }) => { if *is_parenthesized { ("(", ")") diff --git a/crates/ruff_python_ast/src/comparable.rs b/crates/ruff_python_ast/src/comparable.rs index c0dc74b4577079..276894f6a98349 100644 --- a/crates/ruff_python_ast/src/comparable.rs +++ b/crates/ruff_python_ast/src/comparable.rs @@ -977,6 +977,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> { elt, generators, range: _, + parenthesized: _, }) => Self::GeneratorExp(ExprGeneratorExp { elt: elt.into(), generators: generators.iter().map(Into::into).collect(), @@ -1072,7 +1073,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> { elts, ctx: _, range: _, - is_parenthesized: _, + parenthesized: _, }) => Self::Tuple(ExprTuple { elts: elts.iter().map(Into::into).collect(), }), diff --git a/crates/ruff_python_ast/src/helpers.rs b/crates/ruff_python_ast/src/helpers.rs index 6a8983b4fe4a30..844da603902c49 100644 --- a/crates/ruff_python_ast/src/helpers.rs +++ b/crates/ruff_python_ast/src/helpers.rs @@ -183,6 +183,7 @@ pub fn any_over_expr(expr: &Expr, func: &dyn Fn(&Expr) -> bool) -> bool { elt, generators, range: _, + parenthesized: _, }) => { any_over_expr(elt, func) || generators.iter().any(|generator| { @@ -1423,7 +1424,7 @@ pub fn pep_604_union(elts: &[Expr]) -> Expr { elts: vec![], ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, }), [Expr::Tuple(ast::ExprTuple { elts, .. })] => pep_604_union(elts), [elt] => elt.clone(), @@ -1458,7 +1459,7 @@ pub fn typing_union(elts: &[Expr], binding: String) -> Expr { elts: vec![], ctx: ExprContext::Load, range: TextRange::default(), - is_parenthesized: true, + parenthesized: true, }), [Expr::Tuple(ast::ExprTuple { elts, .. })] => typing_union(elts, binding), [elt] => elt.clone(), diff --git a/crates/ruff_python_ast/src/node.rs b/crates/ruff_python_ast/src/node.rs index 6afb05faa4a1a1..90e4b61c545ece 100644 --- a/crates/ruff_python_ast/src/node.rs +++ b/crates/ruff_python_ast/src/node.rs @@ -2430,6 +2430,7 @@ impl AstNode for ast::ExprGeneratorExp { elt, generators, range: _, + parenthesized: _, } = self; visitor.visit_expr(elt); for comprehension in generators { @@ -3256,7 +3257,7 @@ impl AstNode for ast::ExprTuple { elts, ctx: _, range: _, - is_parenthesized: _, + parenthesized: _, } = self; for expr in elts { diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 83d8770a7f7580..d99046114733a8 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -841,6 +841,7 @@ pub struct ExprGeneratorExp { pub range: TextRange, pub elt: Box, pub generators: Vec, + pub parenthesized: bool, } impl From for Expr { @@ -1797,7 +1798,7 @@ pub struct ExprTuple { pub ctx: ExprContext, /// Whether the tuple is parenthesized in the source code. - pub is_parenthesized: bool, + pub parenthesized: bool, } impl From for Expr { @@ -3882,7 +3883,7 @@ mod tests { assert_eq!(std::mem::size_of::(), 48); assert_eq!(std::mem::size_of::(), 8); assert_eq!(std::mem::size_of::(), 48); - assert_eq!(std::mem::size_of::(), 40); + assert_eq!(std::mem::size_of::(), 48); assert_eq!(std::mem::size_of::(), 32); assert_eq!(std::mem::size_of::(), 32); assert_eq!(std::mem::size_of::(), 24); diff --git a/crates/ruff_python_ast/src/visitor.rs b/crates/ruff_python_ast/src/visitor.rs index d0c1244c0db633..1c41bdd14674bb 100644 --- a/crates/ruff_python_ast/src/visitor.rs +++ b/crates/ruff_python_ast/src/visitor.rs @@ -441,6 +441,7 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) { elt, generators, range: _, + parenthesized: _, }) => { for comprehension in generators { visitor.visit_comprehension(comprehension); @@ -539,7 +540,7 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) { elts, ctx, range: _, - is_parenthesized: _, + parenthesized: _, }) => { for expr in elts { visitor.visit_expr(expr); diff --git a/crates/ruff_python_ast/src/visitor/transformer.rs b/crates/ruff_python_ast/src/visitor/transformer.rs index fb1e5bac170e64..3aa2622cebd258 100644 --- a/crates/ruff_python_ast/src/visitor/transformer.rs +++ b/crates/ruff_python_ast/src/visitor/transformer.rs @@ -428,6 +428,7 @@ pub fn walk_expr(visitor: &V, expr: &mut Expr) { elt, generators, range: _, + parenthesized: _, }) => { for comprehension in generators { visitor.visit_comprehension(comprehension); @@ -528,7 +529,7 @@ pub fn walk_expr(visitor: &V, expr: &mut Expr) { elts, ctx, range: _, - is_parenthesized: _, + parenthesized: _, }) => { for expr in elts { visitor.visit_expr(expr); diff --git a/crates/ruff_python_codegen/src/generator.rs b/crates/ruff_python_codegen/src/generator.rs index 934a9f39847bbe..4358bf61314902 100644 --- a/crates/ruff_python_codegen/src/generator.rs +++ b/crates/ruff_python_codegen/src/generator.rs @@ -970,6 +970,7 @@ impl<'a> Generator<'a> { Expr::GeneratorExp(ast::ExprGeneratorExp { elt, generators, + parenthesized: _, range: _, }) => { self.p("("); @@ -1037,6 +1038,7 @@ impl<'a> Generator<'a> { elt, generators, range: _, + parenthesized: _, })], [], ) = (arguments.args.as_ref(), arguments.keywords.as_ref()) diff --git a/crates/ruff_python_formatter/src/comments/placement.rs b/crates/ruff_python_formatter/src/comments/placement.rs index d19ed7d6772f08..44698b0056880b 100644 --- a/crates/ruff_python_formatter/src/comments/placement.rs +++ b/crates/ruff_python_formatter/src/comments/placement.rs @@ -12,7 +12,6 @@ use ruff_source_file::Locator; use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; use crate::comments::visitor::{CommentPlacement, DecoratedComment}; -use crate::expression::expr_generator_exp::is_generator_parenthesized; use crate::expression::expr_slice::{assign_comment_in_slice, ExprSliceCommentSection}; use crate::other::parameters::{ assign_argument_separator_comment_placement, find_parameter_separators, @@ -316,12 +315,10 @@ fn handle_enclosed_comment<'a>( | AnyNodeRef::ExprListComp(_) | AnyNodeRef::ExprSetComp(_) => handle_bracketed_end_of_line_comment(comment, locator), AnyNodeRef::ExprTuple(ast::ExprTuple { - is_parenthesized: true, + parenthesized: true, .. }) => handle_bracketed_end_of_line_comment(comment, locator), - AnyNodeRef::ExprGeneratorExp(generator) - if is_generator_parenthesized(generator, locator.contents()) => - { + AnyNodeRef::ExprGeneratorExp(generator) if generator.parenthesized => { handle_bracketed_end_of_line_comment(comment, locator) } _ => CommentPlacement::Default(comment), diff --git a/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs b/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs index 4d3de0402e9072..fcf75f47713e37 100644 --- a/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs @@ -1,8 +1,6 @@ use ruff_formatter::{format_args, write, FormatRuleWithOptions}; use ruff_python_ast::AnyNodeRef; use ruff_python_ast::ExprGeneratorExp; -use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; -use ruff_text_size::{Ranged, TextRange}; use crate::comments::SourceComment; use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses}; @@ -42,6 +40,7 @@ impl FormatNodeRule for FormatExprGeneratorExp { range: _, elt, generators, + parenthesized: is_parenthesized, } = item; let joined = format_with(|f| { @@ -55,7 +54,7 @@ impl FormatNodeRule for FormatExprGeneratorExp { if self.parentheses == GeneratorExpParentheses::Preserve && dangling.is_empty() - && !is_generator_parenthesized(item, f.context().source()) + && !is_parenthesized { write!( f, @@ -101,37 +100,3 @@ impl NeedsParentheses for ExprGeneratorExp { } } } - -/// Return `true` if a generator is parenthesized in the source code. -pub(crate) fn is_generator_parenthesized(generator: &ExprGeneratorExp, source: &str) -> bool { - // Count the number of open parentheses between the start of the generator and the first element. - let open_parentheses_count = SimpleTokenizer::new( - source, - TextRange::new(generator.start(), generator.elt.start()), - ) - .skip_trivia() - .filter(|token| token.kind() == SimpleTokenKind::LParen) - .count(); - if open_parentheses_count == 0 { - return false; - } - - // Count the number of parentheses between the end of the generator and its trailing comma. - let close_parentheses_count = SimpleTokenizer::new( - source, - TextRange::new( - generator.elt.end(), - generator - .generators - .first() - .map_or(generator.end(), Ranged::start), - ), - ) - .skip_trivia() - .filter(|token| token.kind() == SimpleTokenKind::RParen) - .count(); - - // If the number of open parentheses is greater than the number of close parentheses, the - // generator is parenthesized. - open_parentheses_count > close_parentheses_count -} diff --git a/crates/ruff_python_formatter/src/expression/expr_tuple.rs b/crates/ruff_python_formatter/src/expression/expr_tuple.rs index 399016ca091e96..536a03b45d04a1 100644 --- a/crates/ruff_python_formatter/src/expression/expr_tuple.rs +++ b/crates/ruff_python_formatter/src/expression/expr_tuple.rs @@ -116,7 +116,7 @@ impl FormatNodeRule for FormatExprTuple { elts, ctx: _, range: _, - is_parenthesized, + parenthesized: is_parenthesized, } = item; let comments = f.context().comments().clone(); diff --git a/crates/ruff_python_formatter/src/expression/mod.rs b/crates/ruff_python_formatter/src/expression/mod.rs index 8698a57f20b213..0b8291a7d4fbba 100644 --- a/crates/ruff_python_formatter/src/expression/mod.rs +++ b/crates/ruff_python_formatter/src/expression/mod.rs @@ -14,7 +14,6 @@ use ruff_text_size::Ranged; use crate::builders::parenthesize_if_expands; use crate::comments::{leading_comments, trailing_comments, LeadingDanglingTrailingComments}; use crate::context::{NodeLevel, WithNodeLevel}; -use crate::expression::expr_generator_exp::is_generator_parenthesized; use crate::expression::parentheses::{ is_expression_parenthesized, optional_parentheses, parenthesized, NeedsParentheses, OptionalParentheses, Parentheses, Parenthesize, @@ -662,7 +661,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> { } Expr::Tuple(ast::ExprTuple { - is_parenthesized: true, + parenthesized: true, .. }) => { self.any_parenthesized_expressions = true; @@ -670,9 +669,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> { return; } - Expr::GeneratorExp(generator) - if is_generator_parenthesized(generator, self.context.source()) => - { + Expr::GeneratorExp(generator) if generator.parenthesized => { self.any_parenthesized_expressions = true; // The values are always parenthesized, don't visit. return; @@ -1038,11 +1035,7 @@ pub(crate) fn has_own_parentheses( Some(OwnParentheses::NonEmpty) } - Expr::GeneratorExp(generator) - if is_generator_parenthesized(generator, context.source()) => - { - Some(OwnParentheses::NonEmpty) - } + Expr::GeneratorExp(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, .. }) => { @@ -1055,7 +1048,7 @@ pub(crate) fn has_own_parentheses( Expr::Tuple( tuple @ ast::ExprTuple { - is_parenthesized: true, + parenthesized: true, .. }, ) => { diff --git a/crates/ruff_python_parser/src/context.rs b/crates/ruff_python_parser/src/context.rs index e7c101b0c0deb1..fa30b1d84261fd 100644 --- a/crates/ruff_python_parser/src/context.rs +++ b/crates/ruff_python_parser/src/context.rs @@ -6,13 +6,13 @@ pub(crate) fn set_context(expr: Expr, ctx: ExprContext) -> Expr { Expr::Tuple(ast::ExprTuple { elts, range, - is_parenthesized, + parenthesized: is_parenthesized, ctx: _, }) => ast::ExprTuple { elts: elts.into_iter().map(|elt| set_context(elt, ctx)).collect(), range, ctx, - is_parenthesized, + parenthesized: is_parenthesized, } .into(), diff --git a/crates/ruff_python_parser/src/python.lalrpop b/crates/ruff_python_parser/src/python.lalrpop index 4cc52d60d8b3d4..b10080e1e45e05 100644 --- a/crates/ruff_python_parser/src/python.lalrpop +++ b/crates/ruff_python_parser/src/python.lalrpop @@ -484,7 +484,7 @@ MatchStatement: ast::Stmt = { elts: vec![subject.into()], ctx: ast::ExprContext::Load, range: (tuple_location..tuple_end_location).into(), - is_parenthesized: false + parenthesized: false }, )), cases, @@ -508,7 +508,7 @@ MatchStatement: ast::Stmt = { elts, ctx: ast::ExprContext::Load, range: (tuple_location..tuple_end_location).into(), - is_parenthesized: false + parenthesized: false }, )), cases, @@ -1575,7 +1575,7 @@ SubscriptList: crate::parser::ParenthesizedExpr = { elts: vec![s1.into()], ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: false + parenthesized: false }.into() }, > ","? => { @@ -1584,7 +1584,7 @@ SubscriptList: crate::parser::ParenthesizedExpr = { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: false + parenthesized: false }.into() } }; @@ -1734,7 +1734,7 @@ Atom: crate::parser::ParenthesizedExpr = { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: true + parenthesized: true }.into() } }, @@ -1756,7 +1756,7 @@ Atom: crate::parser::ParenthesizedExpr = { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: true + parenthesized: true }.into()) } }, @@ -1764,7 +1764,7 @@ Atom: crate::parser::ParenthesizedExpr = { elts: Vec::new(), ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: true + parenthesized: true }.into(), "(" ")" => crate::parser::ParenthesizedExpr { expr: e.into(), @@ -1774,6 +1774,7 @@ Atom: crate::parser::ParenthesizedExpr = { elt: Box::new(elt.into()), generators, range: (location..end_location).into(), + parenthesized: true }.into(), "(" "**" > ")" =>? { Err(LexicalError::new( @@ -1871,7 +1872,7 @@ GenericList: crate::parser::ParenthesizedExpr = { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: false + parenthesized: false }.into() } } @@ -1924,7 +1925,8 @@ FunctionArgument: (Option<(TextSize, TextSize, Option)>, ast::E ast::ExprGeneratorExp { elt: Box::new(elt.into()), generators, - range: (location..end_location).into() + range: (location..end_location).into(), + parenthesized: false } ), None => elt.into(), diff --git a/crates/ruff_python_parser/src/python.rs b/crates/ruff_python_parser/src/python.rs index c1b6b25387b920..bd4535bdc69e0a 100644 --- a/crates/ruff_python_parser/src/python.rs +++ b/crates/ruff_python_parser/src/python.rs @@ -1,5 +1,5 @@ // auto-generated: "lalrpop 0.20.0" -// sha3: 7a000e58d9f27e971b204e2e53ef25a811c300174be0b0a1b9dfd89dddc441fb +// sha3: d64ca7ff27121baee9d7a1b4d0f341932391a365fe75f115987b05bf2aaf538e use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; use ruff_python_ast::{self as ast, Int, IpyEscapeKind}; use crate::{ @@ -33939,7 +33939,7 @@ fn __action86< elts: vec![subject.into()], ctx: ast::ExprContext::Load, range: (tuple_location..tuple_end_location).into(), - is_parenthesized: false + parenthesized: false }, )), cases, @@ -33984,7 +33984,7 @@ fn __action87< elts, ctx: ast::ExprContext::Load, range: (tuple_location..tuple_end_location).into(), - is_parenthesized: false + parenthesized: false }, )), cases, @@ -36229,7 +36229,7 @@ fn __action208< elts: vec![s1.into()], ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: false + parenthesized: false }.into() } } @@ -36252,7 +36252,7 @@ fn __action209< elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: false + parenthesized: false }.into() } } @@ -36800,7 +36800,8 @@ fn __action242< ast::ExprGeneratorExp { elt: Box::new(elt.into()), generators, - range: (location..end_location).into() + range: (location..end_location).into(), + parenthesized: false } ), None => elt.into(), @@ -37057,7 +37058,7 @@ fn __action259< elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: false + parenthesized: false }.into() } } @@ -37116,7 +37117,7 @@ fn __action262< elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: false + parenthesized: false }.into() } } @@ -41310,7 +41311,7 @@ fn __action553< elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: true + parenthesized: true }.into() } } @@ -41350,7 +41351,7 @@ fn __action554< elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: true + parenthesized: true }.into()) } } @@ -41372,7 +41373,7 @@ fn __action555< elts: Vec::new(), ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: true + parenthesized: true }.into() } @@ -41413,6 +41414,7 @@ fn __action557< elt: Box::new(elt.into()), generators, range: (location..end_location).into(), + parenthesized: true }.into() } @@ -42054,7 +42056,7 @@ fn __action596< elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: true + parenthesized: true }.into()) } } @@ -42076,7 +42078,7 @@ fn __action597< elts: Vec::new(), ctx: ast::ExprContext::Load, range: (location..end_location).into(), - is_parenthesized: true + parenthesized: true }.into() } @@ -42117,6 +42119,7 @@ fn __action599< elt: Box::new(elt.into()), generators, range: (location..end_location).into(), + parenthesized: true }.into() } diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_attribute.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_attribute.snap index af9de33825bcc7..76cec0d3a443a3 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_attribute.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_attribute.snap @@ -55,7 +55,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_for.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_for.snap index a9b63f3d444fa0..8dcbeb2c5d5b67 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_for.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_for.snap @@ -44,7 +44,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), body: [ diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_list.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_list.snap index 5d9d5fbbbb9b38..db36fdb708abb4 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_list.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_list.snap @@ -60,7 +60,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_list_comp.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_list_comp.snap index c0d52f8c77e30f..1e53db43787630 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_list_comp.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_list_comp.snap @@ -65,7 +65,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ifs: [], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_name.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_name.snap index 191a8f2a9ae0e6..5370e550a8b9f8 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_name.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_name.snap @@ -45,7 +45,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_set_comp.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_set_comp.snap index a8f8ceb524cebd..0ddedadeb0c51f 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_set_comp.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_set_comp.snap @@ -65,7 +65,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ifs: [], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_starred.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_starred.snap index ed0ee653409b56..7e1d7b5eb5583f 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_starred.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_starred.snap @@ -33,7 +33,7 @@ expression: parse_ast ), ], ctx: Store, - is_parenthesized: true, + parenthesized: true, }, ), ], @@ -67,7 +67,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_subscript.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_subscript.snap index febf2979877938..d0ba09c0fc2bd4 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_subscript.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_subscript.snap @@ -58,7 +58,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_tuple.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_tuple.snap index a4680be133a322..125ab247865918 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_tuple.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__assign_tuple.snap @@ -27,7 +27,7 @@ expression: parse_ast ), ], ctx: Store, - is_parenthesized: true, + parenthesized: true, }, ), ], @@ -61,7 +61,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__aug_assign_attribute.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__aug_assign_attribute.snap index 77bd48860b73e1..9a2abb4150a5f1 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__aug_assign_attribute.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__aug_assign_attribute.snap @@ -54,7 +54,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__aug_assign_subscript.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__aug_assign_subscript.snap index 0cde13317cab31..c6cf4f55045e0b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__aug_assign_subscript.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__context__tests__aug_assign_subscript.snap @@ -57,7 +57,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__invalid__tests__ok_tuple.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__invalid__tests__ok_tuple.snap index d77047278e83d4..9f05e6bea1e8f8 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__invalid__tests__ok_tuple.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__invalid__tests__ok_tuple.snap @@ -35,7 +35,7 @@ Ok( ), ], ctx: Store, - is_parenthesized: true, + parenthesized: true, }, ), ], @@ -69,7 +69,7 @@ Ok( ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings.snap index c64479173912c3..a0cc5653a72d8b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings.snap @@ -111,7 +111,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), debug_text: None, @@ -502,7 +502,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), debug_text: Some( diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__generator_expression_argument.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__generator_expression_argument.snap index 87a7eb9f8089c2..df4298d8de2518 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__generator_expression_argument.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__generator_expression_argument.snap @@ -146,13 +146,14 @@ Call( ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ifs: [], is_async: false, }, ], + parenthesized: false, }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match.snap index c6fd80ac699c8c..8cb01387b939c2 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match.snap @@ -469,7 +469,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), cases: [ @@ -522,7 +522,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), cases: [ @@ -575,7 +575,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), cases: [ diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match_as_identifier.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match_as_identifier.snap index a7b61e936d3cdd..1fd737b95feeca 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match_as_identifier.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match_as_identifier.snap @@ -52,7 +52,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), }, @@ -106,7 +106,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), }, @@ -387,7 +387,7 @@ expression: parse_suite(source).unwrap() range: 298..300, elts: [], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ], @@ -428,7 +428,7 @@ expression: parse_suite(source).unwrap() range: 329..331, elts: [], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ], @@ -509,7 +509,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), ctx: Load, @@ -553,7 +553,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parenthesized_with_statement.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parenthesized_with_statement.snap index 33f8e9f1037eba..689cbc611181f6 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parenthesized_with_statement.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parenthesized_with_statement.snap @@ -171,7 +171,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: Some( @@ -221,7 +221,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: Some( diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class_generic_types.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class_generic_types.snap index 321abd4ba2329d..49c4bfd3382c0e 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class_generic_types.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class_generic_types.snap @@ -143,7 +143,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_double_list_comprehension.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_double_list_comprehension.snap index def5b3384f9f44..d939442291a492 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_double_list_comprehension.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_double_list_comprehension.snap @@ -35,7 +35,7 @@ ListComp( ), ], ctx: Store, - is_parenthesized: false, + parenthesized: false, }, ), iter: Name( diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_function_definition.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_function_definition.snap index 97937d913481df..5b7a2bab214c99 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_function_definition.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_function_definition.snap @@ -254,7 +254,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_generator_comprehension.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_generator_comprehension.snap index 134f99c6885853..556bfa858beb9b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_generator_comprehension.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_generator_comprehension.snap @@ -33,5 +33,6 @@ GeneratorExp( is_async: false, }, ], + parenthesized: true, }, ) diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_if_else_generator_comprehension.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_if_else_generator_comprehension.snap index 0ef98fab3f6b1c..ea82d262be1e01 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_if_else_generator_comprehension.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_if_else_generator_comprehension.snap @@ -52,5 +52,6 @@ GeneratorExp( is_async: false, }, ], + parenthesized: true, }, ) diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_named_expression_generator_comprehension.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_named_expression_generator_comprehension.snap index 00cb053f1a0198..eb9aec31ec03dc 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_named_expression_generator_comprehension.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_named_expression_generator_comprehension.snap @@ -59,5 +59,6 @@ GeneratorExp( is_async: false, }, ], + parenthesized: true, }, ) diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_tuples.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_tuples.snap index bd90f04a7f5411..8cb747325c5eec 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_tuples.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_tuples.snap @@ -27,7 +27,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Store, - is_parenthesized: false, + parenthesized: false, }, ), ], @@ -53,7 +53,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap index df5282e180aa3a..ab784f56be1f09 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap @@ -354,7 +354,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, @@ -439,7 +439,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, @@ -486,7 +486,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ), @@ -540,7 +540,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__patma.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__patma.snap index d25e5fefe94a2c..2b527edb994ec0 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__patma.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__patma.snap @@ -1659,7 +1659,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), cases: [ @@ -2149,7 +2149,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), cases: [ @@ -3289,7 +3289,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), cases: [ @@ -3388,7 +3388,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), cases: [ @@ -3470,7 +3470,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), cases: [ @@ -3547,7 +3547,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), cases: [ @@ -3641,7 +3641,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), cases: [ diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__star_index.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__star_index.snap index aad39083aeb66b..340b3ea3d5809c 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__star_index.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__star_index.snap @@ -66,7 +66,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), ctx: Load, @@ -129,7 +129,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), ctx: Store, @@ -190,7 +190,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), ctx: Load, @@ -256,7 +256,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__tuple.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__tuple.snap index 46c04c10ba20fc..73d7183402cdb6 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__tuple.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__tuple.snap @@ -26,7 +26,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), }, @@ -54,7 +54,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, @@ -67,7 +67,7 @@ expression: parse_ast range: 10..12, elts: [], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, @@ -88,7 +88,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, @@ -116,7 +116,7 @@ expression: parse_ast ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__type_as_identifier.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__type_as_identifier.snap index a735975631041c..6ac529f01fb1fc 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__type_as_identifier.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__type_as_identifier.snap @@ -52,7 +52,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), }, @@ -106,7 +106,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), }, @@ -387,7 +387,7 @@ expression: parse_suite(source).unwrap() range: 283..285, elts: [], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ], @@ -428,7 +428,7 @@ expression: parse_suite(source).unwrap() range: 312..314, elts: [], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ], @@ -509,7 +509,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: false, + parenthesized: false, }, ), ctx: Load, @@ -553,7 +553,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__with_statement.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__with_statement.snap index 3dc0ccdb0e1ed6..2d6cde0597c6d1 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__with_statement.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__with_statement.snap @@ -275,7 +275,7 @@ expression: parse_suite(source).unwrap() range: 133..135, elts: [], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: None, @@ -302,7 +302,7 @@ expression: parse_suite(source).unwrap() range: 147..149, elts: [], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: Some( @@ -435,7 +435,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: Some( @@ -526,7 +526,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: Some( @@ -575,7 +575,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: None, @@ -616,7 +616,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: Some( @@ -673,7 +673,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: None, @@ -722,7 +722,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: Some( @@ -884,7 +884,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: None, @@ -952,7 +952,7 @@ expression: parse_suite(source).unwrap() ), ], ctx: Load, - is_parenthesized: true, + parenthesized: true, }, ), optional_vars: Some(