diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index 6e44c85c154d4..1e822a4775561 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -134,6 +134,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { elts, ctx, range: _, + parenthesized: _, }) | Expr::List(ast::ExprList { elts, @@ -1451,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 c8753bd961a6a..970f33e2aa08b 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,6 +1328,7 @@ where elts, ctx, range: _, + 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 8357b6670b38c..3f708002e2c7e 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,6 +109,7 @@ fn type_pattern(elts: Vec<&Expr>) -> Expr { elts: elts.into_iter().cloned().collect(), ctx: ExprContext::Load, range: TextRange::default(), + 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 b3031ff97e617..ba2dc033cf94e 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,6 +173,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) { .collect(), ctx: ExprContext::Load, range: TextRange::default(), + 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 08040938a7eca..b3a49d819732c 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,6 +72,7 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Exp elts, range: _, ctx: _, + parenthesized: _, }) = slice.as_ref() { for expr in elts { @@ -123,6 +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, + parenthesized: true, })), range: TextRange::default(), ctx: ExprContext::Load, @@ -148,6 +150,7 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Exp elts, range: TextRange::default(), ctx: ExprContext::Load, + 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 caf00e7a219d6..d4cd2cde2c9a8 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,6 +130,7 @@ pub(crate) fn unnecessary_type_union<'a>(checker: &mut Checker, union: &'a Expr) .collect(), ctx: ExprContext::Load, range: TextRange::default(), + parenthesized: true, })), ctx: ExprContext::Load, range: TextRange::default(), @@ -151,6 +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(), + 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 eb2608ff79792..8a575dc9ff52d 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,6 +337,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) { .collect(), ctx: ExprContext::Load, range: TextRange::default(), + parenthesized: true, }); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( format!("({})", checker.generator().expr(&node)), @@ -444,6 +445,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) { elts: elts.clone(), ctx: ExprContext::Load, range: TextRange::default(), + 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 5256d69e2f752..88a08dd38e6eb 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,6 +428,7 @@ pub(crate) fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) { .collect(), ctx: ExprContext::Load, range: TextRange::default(), + parenthesized: true, }; let node1 = ast::ExprName { id: "isinstance".into(), @@ -543,6 +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(), + parenthesized: true, }; let node1 = ast::ExprName { id: id.into(), @@ -718,7 +720,7 @@ fn get_short_circuit_edit( generator.expr(expr) }; Edit::range_replacement( - if matches!(expr, Expr::Tuple(ast::ExprTuple { elts, ctx: _, range: _}) 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 09475ad8abd3b..30273ace9d9ce 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 0c85d1a8ed0c4..dc86eb4dd28f6 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,6 +305,7 @@ fn assignment_targets_from_expr<'a>( ctx: ExprContext::Store, elts, range: _, + 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 25f36d63a1bd9..df3ab969240c7 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,6 +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, + 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 8477e775b7649..dca5dfe715f3d 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,6 +127,7 @@ fn tuple_diagnostic(checker: &mut Checker, tuple: &ast::ExprTuple, aliases: &[&E elts: remaining, ctx: ExprContext::Load, range: TextRange::default(), + 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 419e6bacacbc7..43ffafa3d5df2 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,6 +141,7 @@ fn tuple_diagnostic(checker: &mut Checker, tuple: &ast::ExprTuple, aliases: &[&E elts: remaining, ctx: ExprContext::Load, range: TextRange::default(), + 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 29f9039d2109a..1966ce1b35055 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,6 +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, + 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 d1fc37a7239fe..1eb6bbaf6ff2d 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs @@ -347,6 +347,7 @@ fn make_suggestion(group: &AppendGroup, generator: Generator) -> String { elts, ctx: ast::ExprContext::Load, range: TextRange::default(), + 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 263ff68dc9258..db8913497535b 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,6 +162,7 @@ fn concatenate_expressions(expr: &Expr) -> Option<(Expr, Type)> { elts: new_elts, ctx: ExprContext::Load, range: TextRange::default(), + 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 897a0e4855077..45abda9067641 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/never_union.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/never_union.rs @@ -116,6 +116,7 @@ pub(crate) fn never_union(checker: &mut Checker, expr: &Expr) { elts, ctx: _, range: _, + parenthesized: _, }) = slice.as_ref() else { return; @@ -157,6 +158,7 @@ pub(crate) fn never_union(checker: &mut Checker, expr: &Expr) { elts: rest, ctx: ast::ExprContext::Load, range: TextRange::default(), + 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 c84b00ce4a124..1348760400262 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs @@ -134,23 +134,23 @@ impl InferredMemberType { /// single-line tuple literals *can* be unparenthesized. /// We keep the original AST node around for the /// Tuple variant so that this can be queried later. -#[derive(Debug)] -pub(super) enum SequenceKind<'a> { +#[derive(Copy, Clone, Debug)] +pub(super) enum SequenceKind { List, Set, - Tuple(&'a ast::ExprTuple), + Tuple { parenthesized: bool }, } -impl SequenceKind<'_> { +impl SequenceKind { // N.B. We only need the source code for the Tuple variant here, // but if you already have a `Locator` instance handy, // getting the source code is very cheap. - fn surrounding_brackets(&self, source: &str) -> (&'static str, &'static str) { + fn surrounding_brackets(self) -> (&'static str, &'static str) { match self { Self::List => ("[", "]"), Self::Set => ("{", "}"), - Self::Tuple(ast_node) => { - if ast_node.is_parenthesized(source) { + Self::Tuple { parenthesized } => { + if parenthesized { ("(", ")") } else { ("", "") @@ -159,19 +159,19 @@ impl SequenceKind<'_> { } } - const fn opening_token_for_multiline_definition(&self) -> TokenKind { + const fn opening_token_for_multiline_definition(self) -> TokenKind { match self { Self::List => TokenKind::Lsqb, Self::Set => TokenKind::Lbrace, - Self::Tuple(_) => TokenKind::Lpar, + Self::Tuple { .. } => TokenKind::Lpar, } } - const fn closing_token_for_multiline_definition(&self) -> TokenKind { + const fn closing_token_for_multiline_definition(self) -> TokenKind { match self { Self::List => TokenKind::Rsqb, Self::Set => TokenKind::Rbrace, - Self::Tuple(_) => TokenKind::Rpar, + Self::Tuple { .. } => TokenKind::Rpar, } } } @@ -217,7 +217,7 @@ impl<'a> SequenceElements<'a> { /// that can be inserted into the /// source code as a `range_replacement` autofix. pub(super) fn sort_single_line_elements_sequence( - kind: &SequenceKind, + kind: SequenceKind, elts: &[ast::Expr], elements: &[&str], locator: &Locator, @@ -225,7 +225,7 @@ pub(super) fn sort_single_line_elements_sequence( ) -> String { let element_pairs = SequenceElements::new(elements, elts); let last_item_index = element_pairs.last_item_index(); - let (opening_paren, closing_paren) = kind.surrounding_brackets(locator.contents()); + let (opening_paren, closing_paren) = kind.surrounding_brackets(); let mut result = String::from(opening_paren); // We grab the original source-code ranges using `locator.slice()` // rather than using the expression generator, as this approach allows @@ -334,7 +334,7 @@ impl MultilineStringSequenceValue { /// Return `None` if the analysis fails for whatever reason. pub(super) fn from_source_range( range: TextRange, - kind: &SequenceKind, + kind: SequenceKind, locator: &Locator, ) -> Option { // Parse the multiline string sequence using the raw tokens. @@ -486,7 +486,7 @@ impl Ranged for MultilineStringSequenceValue { /// in the original source code. fn collect_string_sequence_lines( range: TextRange, - kind: &SequenceKind, + kind: SequenceKind, locator: &Locator, ) -> Option<(Vec, bool)> { // These first two variables are used for keeping track of state diff --git a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs index 6df5646f6b002..6828874832c04 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs @@ -152,9 +152,13 @@ fn sort_dunder_all(checker: &mut Checker, target: &ast::Expr, node: &ast::Expr) let (elts, range, kind) = match node { ast::Expr::List(ast::ExprList { elts, range, .. }) => (elts, *range, SequenceKind::List), - ast::Expr::Tuple(tuple_node @ ast::ExprTuple { elts, range, .. }) => { - (elts, *range, SequenceKind::Tuple(tuple_node)) - } + ast::Expr::Tuple(tuple_node @ ast::ExprTuple { elts, range, .. }) => ( + elts, + *range, + SequenceKind::Tuple { + parenthesized: tuple_node.parenthesized, + }, + ), _ => return, }; @@ -166,7 +170,7 @@ fn sort_dunder_all(checker: &mut Checker, target: &ast::Expr, node: &ast::Expr) let mut diagnostic = Diagnostic::new(UnsortedDunderAll, range); if let SortClassification::UnsortedAndMaybeFixable { items } = elts_analysis { - if let Some(fix) = create_fix(range, elts, &items, &kind, checker) { + if let Some(fix) = create_fix(range, elts, &items, kind, checker) { diagnostic.set_fix(fix); } } @@ -187,7 +191,7 @@ fn create_fix( range: TextRange, elts: &[ast::Expr], string_items: &[&str], - kind: &SequenceKind, + kind: SequenceKind, checker: &Checker, ) -> Option { let locator = checker.locator(); diff --git a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs index 83248ac9dc0f3..01e4300727892 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs @@ -157,7 +157,9 @@ impl<'a> StringLiteralDisplay<'a> { } } ast::Expr::Tuple(tuple_node @ ast::ExprTuple { elts, range, .. }) => { - let display_kind = DisplayKind::Sequence(SequenceKind::Tuple(tuple_node)); + let display_kind = DisplayKind::Sequence(SequenceKind::Tuple { + parenthesized: tuple_node.parenthesized, + }); Self { elts: Cow::Borrowed(elts), range: *range, @@ -211,7 +213,7 @@ impl<'a> StringLiteralDisplay<'a> { (DisplayKind::Sequence(sequence_kind), true) => { let analyzed_sequence = MultilineStringSequenceValue::from_source_range( self.range(), - sequence_kind, + *sequence_kind, locator, )?; assert_eq!(analyzed_sequence.len(), self.elts.len()); @@ -220,7 +222,7 @@ impl<'a> StringLiteralDisplay<'a> { // Sorting multiline dicts is unsupported (DisplayKind::Dict { .. }, true) => return None, (DisplayKind::Sequence(sequence_kind), false) => sort_single_line_elements_sequence( - sequence_kind, + *sequence_kind, &self.elts, items, locator, @@ -242,7 +244,7 @@ impl<'a> StringLiteralDisplay<'a> { /// Python provides for builtin containers. #[derive(Debug)] enum DisplayKind<'a> { - Sequence(SequenceKind<'a>), + Sequence(SequenceKind), Dict { values: &'a [ast::Expr] }, } diff --git a/crates/ruff_python_ast/src/comparable.rs b/crates/ruff_python_ast/src/comparable.rs index 344bb615ce95e..276894f6a9834 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,6 +1073,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> { elts, ctx: _, range: _, + 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 154be660d37ae..844da603902c4 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,6 +1424,7 @@ pub fn pep_604_union(elts: &[Expr]) -> Expr { elts: vec![], ctx: ExprContext::Load, range: TextRange::default(), + parenthesized: true, }), [Expr::Tuple(ast::ExprTuple { elts, .. })] => pep_604_union(elts), [elt] => elt.clone(), @@ -1457,6 +1459,7 @@ pub fn typing_union(elts: &[Expr], binding: String) -> Expr { elts: vec![], ctx: ExprContext::Load, range: TextRange::default(), + 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 54afd2e040b3e..90e4b61c545ec 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,6 +3257,7 @@ impl AstNode for ast::ExprTuple { elts, ctx: _, range: _, + 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 b6581eef40524..d99046114733a 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -8,7 +8,6 @@ use std::slice::{Iter, IterMut}; use itertools::Itertools; -use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_text_size::{Ranged, TextRange, TextSize}; use crate::{int, LiteralExpressionRef}; @@ -842,6 +841,7 @@ pub struct ExprGeneratorExp { pub range: TextRange, pub elt: Box, pub generators: Vec, + pub parenthesized: bool, } impl From for Expr { @@ -1796,6 +1796,9 @@ pub struct ExprTuple { pub range: TextRange, pub elts: Vec, pub ctx: ExprContext, + + /// Whether the tuple is parenthesized in the source code. + pub parenthesized: bool, } impl From for Expr { @@ -1804,37 +1807,6 @@ impl From for Expr { } } -impl ExprTuple { - /// Return `true` if a tuple is parenthesized in the source code. - pub fn is_parenthesized(&self, source: &str) -> bool { - let Some(elt) = self.elts.first() else { - return true; - }; - - // Count the number of open parentheses between the start of the tuple and the first element. - let open_parentheses_count = - SimpleTokenizer::new(source, TextRange::new(self.start(), 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 first element and its trailing comma. - let close_parentheses_count = - SimpleTokenizer::new(source, TextRange::new(elt.end(), self.end())) - .skip_trivia() - .take_while(|token| token.kind() != SimpleTokenKind::Comma) - .filter(|token| token.kind() == SimpleTokenKind::RParen) - .count(); - - // If the number of open parentheses is greater than the number of close parentheses, the tuple - // is parenthesized. - open_parentheses_count > close_parentheses_count - } -} - /// See also [Slice](https://docs.python.org/3/library/ast.html#ast.Slice) #[derive(Clone, Debug, PartialEq)] pub struct ExprSlice { @@ -3911,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 cd93b4927fd66..1c41bdd14674b 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,6 +540,7 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) { elts, ctx, range: _, + 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 a8e1f8950880f..3aa2622cebd25 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,6 +529,7 @@ pub fn walk_expr(visitor: &V, expr: &mut Expr) { elts, ctx, range: _, + 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 934a9f39847bb..4358bf6131490 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 0033d69206e6d..44698b0056880 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, @@ -315,12 +314,11 @@ fn handle_enclosed_comment<'a>( | AnyNodeRef::ExprSet(_) | AnyNodeRef::ExprListComp(_) | AnyNodeRef::ExprSetComp(_) => handle_bracketed_end_of_line_comment(comment, locator), - AnyNodeRef::ExprTuple(tuple) if tuple.is_parenthesized(locator.contents()) => { - handle_bracketed_end_of_line_comment(comment, locator) - } - AnyNodeRef::ExprGeneratorExp(generator) - if is_generator_parenthesized(generator, locator.contents()) => - { + AnyNodeRef::ExprTuple(ast::ExprTuple { + parenthesized: true, + .. + }) => handle_bracketed_end_of_line_comment(comment, locator), + 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 4d3de0402e907..fcf75f47713e3 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 9db272c611ccd..536a03b45d04a 100644 --- a/crates/ruff_python_formatter/src/expression/expr_tuple.rs +++ b/crates/ruff_python_formatter/src/expression/expr_tuple.rs @@ -116,6 +116,7 @@ impl FormatNodeRule for FormatExprTuple { elts, ctx: _, range: _, + parenthesized: is_parenthesized, } = item; let comments = f.context().comments().clone(); @@ -136,7 +137,7 @@ impl FormatNodeRule for FormatExprTuple { return empty_parenthesized("(", dangling, ")").fmt(f); } [single] => match self.parentheses { - TupleParentheses::Preserve if !item.is_parenthesized(f.context().source()) => { + TupleParentheses::Preserve if !is_parenthesized => { write!(f, [single.format(), token(",")]) } _ => @@ -152,7 +153,7 @@ impl FormatNodeRule for FormatExprTuple { // // Unlike other expression parentheses, tuple parentheses are part of the range of the // tuple itself. - _ if item.is_parenthesized(f.context().source()) + _ if *is_parenthesized && !(self.parentheses == TupleParentheses::NeverPreserve && dangling.is_empty()) => { diff --git a/crates/ruff_python_formatter/src/expression/mod.rs b/crates/ruff_python_formatter/src/expression/mod.rs index ab0deee155f67..0b8291a7d4fbb 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, @@ -661,15 +660,16 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> { return; } - Expr::Tuple(tuple) if tuple.is_parenthesized(self.context.source()) => { + Expr::Tuple(ast::ExprTuple { + parenthesized: true, + .. + }) => { self.any_parenthesized_expressions = true; // The values are always parenthesized, don't visit. 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; @@ -1035,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, .. }) => { @@ -1050,7 +1046,12 @@ pub(crate) fn has_own_parentheses( } } - Expr::Tuple(tuple) if tuple.is_parenthesized(context.source()) => { + Expr::Tuple( + tuple @ ast::ExprTuple { + parenthesized: true, + .. + }, + ) => { if !tuple.elts.is_empty() || context.comments().has_dangling(AnyNodeRef::from(expr)) { Some(OwnParentheses::NonEmpty) } else { diff --git a/crates/ruff_python_parser/src/context.rs b/crates/ruff_python_parser/src/context.rs index 8620c5849ebfb..fa30b1d84261f 100644 --- a/crates/ruff_python_parser/src/context.rs +++ b/crates/ruff_python_parser/src/context.rs @@ -3,10 +3,16 @@ use ruff_python_ast::{self as ast, Expr, ExprContext}; pub(crate) fn set_context(expr: Expr, ctx: ExprContext) -> Expr { match expr { Expr::Name(ast::ExprName { id, range, .. }) => ast::ExprName { range, id, ctx }.into(), - Expr::Tuple(ast::ExprTuple { elts, range, .. }) => ast::ExprTuple { + Expr::Tuple(ast::ExprTuple { + elts, + range, + parenthesized: is_parenthesized, + ctx: _, + }) => ast::ExprTuple { elts: elts.into_iter().map(|elt| set_context(elt, ctx)).collect(), range, ctx, + parenthesized: is_parenthesized, } .into(), diff --git a/crates/ruff_python_parser/src/parser.rs b/crates/ruff_python_parser/src/parser.rs index bc530a0f7d0db..60a855cc2ef14 100644 --- a/crates/ruff_python_parser/src/parser.rs +++ b/crates/ruff_python_parser/src/parser.rs @@ -1505,4 +1505,20 @@ u"foo" f"bar {baz} really" u"bar" "no" let parse_ast = parse_suite(r#"x = "\N{BACKSPACE}another cool trick""#).unwrap(); insta::assert_debug_snapshot!(parse_ast); } + + #[test] + fn test_tuple() { + let parse_ast = parse_suite( + r#" +a,b +(a,b) +() +(a,) +((a,b)) +"# + .trim(), + ) + .unwrap(); + insta::assert_debug_snapshot!(parse_ast); + } } diff --git a/crates/ruff_python_parser/src/python.lalrpop b/crates/ruff_python_parser/src/python.lalrpop index 34d049a0176c8..b10080e1e45e0 100644 --- a/crates/ruff_python_parser/src/python.lalrpop +++ b/crates/ruff_python_parser/src/python.lalrpop @@ -483,7 +483,8 @@ MatchStatement: ast::Stmt = { ast::ExprTuple { elts: vec![subject.into()], ctx: ast::ExprContext::Load, - range: (tuple_location..tuple_end_location).into() + range: (tuple_location..tuple_end_location).into(), + parenthesized: false }, )), cases, @@ -506,7 +507,8 @@ MatchStatement: ast::Stmt = { ast::ExprTuple { elts, ctx: ast::ExprContext::Load, - range: (tuple_location..tuple_end_location).into() + range: (tuple_location..tuple_end_location).into(), + parenthesized: false }, )), cases, @@ -1573,6 +1575,7 @@ SubscriptList: crate::parser::ParenthesizedExpr = { elts: vec![s1.into()], ctx: ast::ExprContext::Load, range: (location..end_location).into(), + parenthesized: false }.into() }, > ","? => { @@ -1581,6 +1584,7 @@ SubscriptList: crate::parser::ParenthesizedExpr = { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), + parenthesized: false }.into() } }; @@ -1726,7 +1730,12 @@ Atom: crate::parser::ParenthesizedExpr = { } } else { let elts = elts.into_iter().map(ast::Expr::from).collect(); - ast::ExprTuple { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into() }.into() + ast::ExprTuple { + elts, + ctx: ast::ExprContext::Load, + range: (location..end_location).into(), + parenthesized: true + }.into() } }, "(" >> ",")?> )*> ")" =>? { @@ -1743,13 +1752,19 @@ Atom: crate::parser::ParenthesizedExpr = { }) } else { let elts = left.into_iter().flatten().chain([mid]).chain(right).map(ast::Expr::from).collect(); - Ok(ast::ExprTuple { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into() }.into()) + Ok(ast::ExprTuple { + elts, + ctx: ast::ExprContext::Load, + range: (location..end_location).into(), + parenthesized: true + }.into()) } }, "(" ")" => ast::ExprTuple { elts: Vec::new(), ctx: ast::ExprContext::Load, range: (location..end_location).into(), + parenthesized: true }.into(), "(" ")" => crate::parser::ParenthesizedExpr { expr: e.into(), @@ -1759,6 +1774,7 @@ Atom: crate::parser::ParenthesizedExpr = { elt: Box::new(elt.into()), generators, range: (location..end_location).into(), + parenthesized: true }.into(), "(" "**" > ")" =>? { Err(LexicalError::new( @@ -1852,7 +1868,12 @@ GenericList: crate::parser::ParenthesizedExpr = { } } else { let elts = elts.into_iter().map(ast::Expr::from).collect(); - ast::ExprTuple { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into() }.into() + ast::ExprTuple { + elts, + ctx: ast::ExprContext::Load, + range: (location..end_location).into(), + parenthesized: false + }.into() } } } @@ -1904,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 646fcfdeb6891..bd4535bdc69e0 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: 8c85e4bbac54760ed8be03b56a428d76e14d18e6dbde62b424d0b2b5e8e65dbe +// sha3: d64ca7ff27121baee9d7a1b4d0f341932391a365fe75f115987b05bf2aaf538e use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; use ruff_python_ast::{self as ast, Int, IpyEscapeKind}; use crate::{ @@ -33938,7 +33938,8 @@ fn __action86< ast::ExprTuple { elts: vec![subject.into()], ctx: ast::ExprContext::Load, - range: (tuple_location..tuple_end_location).into() + range: (tuple_location..tuple_end_location).into(), + parenthesized: false }, )), cases, @@ -33982,7 +33983,8 @@ fn __action87< ast::ExprTuple { elts, ctx: ast::ExprContext::Load, - range: (tuple_location..tuple_end_location).into() + range: (tuple_location..tuple_end_location).into(), + parenthesized: false }, )), cases, @@ -36227,6 +36229,7 @@ fn __action208< elts: vec![s1.into()], ctx: ast::ExprContext::Load, range: (location..end_location).into(), + parenthesized: false }.into() } } @@ -36249,6 +36252,7 @@ fn __action209< elts, ctx: ast::ExprContext::Load, range: (location..end_location).into(), + parenthesized: false }.into() } } @@ -36796,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(), @@ -37049,7 +37054,12 @@ fn __action259< } } else { let elts = elts.into_iter().map(ast::Expr::from).collect(); - ast::ExprTuple { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into() }.into() + ast::ExprTuple { + elts, + ctx: ast::ExprContext::Load, + range: (location..end_location).into(), + parenthesized: false + }.into() } } } @@ -37103,7 +37113,12 @@ fn __action262< } } else { let elts = elts.into_iter().map(ast::Expr::from).collect(); - ast::ExprTuple { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into() }.into() + ast::ExprTuple { + elts, + ctx: ast::ExprContext::Load, + range: (location..end_location).into(), + parenthesized: false + }.into() } } } @@ -41292,7 +41307,12 @@ fn __action553< } } else { let elts = elts.into_iter().map(ast::Expr::from).collect(); - ast::ExprTuple { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into() }.into() + ast::ExprTuple { + elts, + ctx: ast::ExprContext::Load, + range: (location..end_location).into(), + parenthesized: true + }.into() } } } @@ -41327,7 +41347,12 @@ fn __action554< }) } else { let elts = left.into_iter().flatten().chain([mid]).chain(right).map(ast::Expr::from).collect(); - Ok(ast::ExprTuple { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into() }.into()) + Ok(ast::ExprTuple { + elts, + ctx: ast::ExprContext::Load, + range: (location..end_location).into(), + parenthesized: true + }.into()) } } } @@ -41348,6 +41373,7 @@ fn __action555< elts: Vec::new(), ctx: ast::ExprContext::Load, range: (location..end_location).into(), + parenthesized: true }.into() } @@ -41388,6 +41414,7 @@ fn __action557< elt: Box::new(elt.into()), generators, range: (location..end_location).into(), + parenthesized: true }.into() } @@ -42025,7 +42052,12 @@ fn __action596< }) } else { let elts = left.into_iter().flatten().chain([mid]).chain(right).map(ast::Expr::from).collect(); - Ok(ast::ExprTuple { elts, ctx: ast::ExprContext::Load, range: (location..end_location).into() }.into()) + Ok(ast::ExprTuple { + elts, + ctx: ast::ExprContext::Load, + range: (location..end_location).into(), + parenthesized: true + }.into()) } } } @@ -42046,6 +42078,7 @@ fn __action597< elts: Vec::new(), ctx: ast::ExprContext::Load, range: (location..end_location).into(), + parenthesized: true }.into() } @@ -42086,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 e269b2e4d45ed..76cec0d3a443a 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,6 +55,7 @@ expression: parse_ast ), ], ctx: Load, + 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 d7775fae99876..8dcbeb2c5d5b6 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,6 +44,7 @@ expression: parse_ast ), ], ctx: Load, + 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 436e3f449f885..db36fdb708abb 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,6 +60,7 @@ expression: parse_ast ), ], ctx: Load, + 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 d73b326211c80..1e53db4378763 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,6 +65,7 @@ expression: parse_ast ), ], ctx: Load, + 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 c3b835c27e2ec..5370e550a8b9f 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,6 +45,7 @@ expression: parse_ast ), ], ctx: Load, + 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 f5c256cd2541a..0ddedadeb0c51 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,6 +65,7 @@ expression: parse_ast ), ], ctx: Load, + 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 d6401710ed926..7e1d7b5eb5583 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,6 +33,7 @@ expression: parse_ast ), ], ctx: Store, + parenthesized: true, }, ), ], @@ -66,6 +67,7 @@ expression: parse_ast ), ], ctx: Load, + 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 abdb9e8088c9c..d0ba09c0fc2bd 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,6 +58,7 @@ expression: parse_ast ), ], ctx: Load, + 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 ac332e78f70e9..125ab24786591 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,6 +27,7 @@ expression: parse_ast ), ], ctx: Store, + parenthesized: true, }, ), ], @@ -60,6 +61,7 @@ expression: parse_ast ), ], ctx: Load, + 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 6286c12485136..9a2abb4150a5f 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,6 +54,7 @@ expression: parse_ast ), ], ctx: Load, + 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 6b1feb1798485..c6cf4f55045e0 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,6 +57,7 @@ expression: parse_ast ), ], ctx: Load, + 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 88e7d791f0114..9f05e6bea1e8f 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,6 +35,7 @@ Ok( ), ], ctx: Store, + parenthesized: true, }, ), ], @@ -68,6 +69,7 @@ Ok( ), ], ctx: Load, + 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 a46c03a3d9bc2..a0cc5653a72d8 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,6 +111,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: false, }, ), debug_text: None, @@ -501,6 +502,7 @@ expression: parse_ast ), ], ctx: Load, + 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 08f16c5d09f78..df4298d8de251 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,12 +146,14 @@ Call( ), ], ctx: Load, + 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 545c9396f93b0..8cb01387b939c 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,6 +469,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: false, }, ), cases: [ @@ -521,6 +522,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: false, }, ), cases: [ @@ -573,6 +575,7 @@ expression: parse_ast ), ], ctx: Load, + 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 6591b7c9d0baa..1fd737b95feec 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 @@ -1,6 +1,6 @@ --- source: crates/ruff_python_parser/src/parser.rs -expression: "parse_suite(source, \"\").unwrap()" +expression: parse_suite(source).unwrap() --- [ Expr( @@ -52,6 +52,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: false, }, ), }, @@ -105,6 +106,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: false, }, ), }, @@ -385,6 +387,7 @@ expression: "parse_suite(source, \"\").unwrap()" range: 298..300, elts: [], ctx: Load, + parenthesized: true, }, ), ], @@ -425,6 +428,7 @@ expression: "parse_suite(source, \"\").unwrap()" range: 329..331, elts: [], ctx: Load, + parenthesized: true, }, ), ], @@ -505,6 +509,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: false, }, ), ctx: Load, @@ -548,6 +553,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + 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 0e703191724d8..689cbc611181f 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 @@ -1,6 +1,6 @@ --- source: crates/ruff_python_parser/src/parser.rs -expression: "parse_suite(source, \"\").unwrap()" +expression: parse_suite(source).unwrap() --- [ With( @@ -171,6 +171,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), optional_vars: Some( @@ -220,6 +221,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + 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 8d868ecef23a3..49c4bfd3382c0 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 @@ -1,6 +1,6 @@ --- source: crates/ruff_python_parser/src/parser.rs -expression: "parse_suite(source, \"\").unwrap()" +expression: parse_suite(source).unwrap() --- [ ClassDef( @@ -143,6 +143,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + 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 0440c2f331309..d939442291a49 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,6 +35,7 @@ ListComp( ), ], ctx: Store, + 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 c673e95d9658c..5b7a2bab214c9 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 @@ -1,6 +1,6 @@ --- source: crates/ruff_python_parser/src/parser.rs -expression: "parse_suite(source, \"\").unwrap()" +expression: parse_suite(source).unwrap() --- [ FunctionDef( @@ -254,6 +254,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + 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 134f99c688585..556bfa858beb9 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 0ef98fab3f6b1..ea82d262be1e0 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 00cb053f1a019..eb9aec31ec03d 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 3dd0a471b213c..8cb747325c5ee 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 @@ -1,6 +1,6 @@ --- source: crates/ruff_python_parser/src/parser.rs -expression: "parse_suite(source, \"\").unwrap()" +expression: parse_suite(source).unwrap() --- [ Assign( @@ -27,6 +27,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Store, + parenthesized: false, }, ), ], @@ -52,6 +53,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + 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 7730469ff75ef..ab784f56be1f0 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 @@ -1,6 +1,6 @@ --- source: crates/ruff_python_parser/src/parser.rs -expression: "parse_suite(source, \"\").unwrap()" +expression: parse_suite(source).unwrap() --- [ TypeAlias( @@ -354,6 +354,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), }, @@ -438,6 +439,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), }, @@ -484,6 +486,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), ), @@ -537,6 +540,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + 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 c90e9f1e65a04..2b527edb994ec 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,6 +1659,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: true, }, ), cases: [ @@ -2148,6 +2149,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: true, }, ), cases: [ @@ -3287,6 +3289,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: true, }, ), cases: [ @@ -3385,6 +3388,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: true, }, ), cases: [ @@ -3466,6 +3470,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: false, }, ), cases: [ @@ -3542,6 +3547,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: false, }, ), cases: [ @@ -3635,6 +3641,7 @@ expression: parse_ast ), ], ctx: Load, + 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 3cd99121dedd8..340b3ea3d5809 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,6 +66,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: false, }, ), ctx: Load, @@ -128,6 +129,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: false, }, ), ctx: Store, @@ -188,6 +190,7 @@ expression: parse_ast ), ], ctx: Load, + parenthesized: false, }, ), ctx: Load, @@ -253,6 +256,7 @@ expression: parse_ast ), ], ctx: Load, + 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 new file mode 100644 index 0000000000000..73d7183402cdb --- /dev/null +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__tuple.snap @@ -0,0 +1,124 @@ +--- +source: crates/ruff_python_parser/src/parser.rs +expression: parse_ast +--- +[ + Expr( + StmtExpr { + range: 0..3, + value: Tuple( + ExprTuple { + range: 0..3, + elts: [ + Name( + ExprName { + range: 0..1, + id: "a", + ctx: Load, + }, + ), + Name( + ExprName { + range: 2..3, + id: "b", + ctx: Load, + }, + ), + ], + ctx: Load, + parenthesized: false, + }, + ), + }, + ), + Expr( + StmtExpr { + range: 4..9, + value: Tuple( + ExprTuple { + range: 4..9, + elts: [ + Name( + ExprName { + range: 5..6, + id: "a", + ctx: Load, + }, + ), + Name( + ExprName { + range: 7..8, + id: "b", + ctx: Load, + }, + ), + ], + ctx: Load, + parenthesized: true, + }, + ), + }, + ), + Expr( + StmtExpr { + range: 10..12, + value: Tuple( + ExprTuple { + range: 10..12, + elts: [], + ctx: Load, + parenthesized: true, + }, + ), + }, + ), + Expr( + StmtExpr { + range: 13..17, + value: Tuple( + ExprTuple { + range: 13..17, + elts: [ + Name( + ExprName { + range: 14..15, + id: "a", + ctx: Load, + }, + ), + ], + ctx: Load, + parenthesized: true, + }, + ), + }, + ), + Expr( + StmtExpr { + range: 18..25, + value: Tuple( + ExprTuple { + range: 19..24, + elts: [ + Name( + ExprName { + range: 20..21, + id: "a", + ctx: Load, + }, + ), + Name( + ExprName { + range: 22..23, + id: "b", + ctx: Load, + }, + ), + ], + ctx: Load, + 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 0296e7ad0511e..6ac529f01fb1f 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 @@ -1,6 +1,6 @@ --- source: crates/ruff_python_parser/src/parser.rs -expression: "parse_suite(source, \"\").unwrap()" +expression: parse_suite(source).unwrap() --- [ Expr( @@ -52,6 +52,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: false, }, ), }, @@ -105,6 +106,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: false, }, ), }, @@ -385,6 +387,7 @@ expression: "parse_suite(source, \"\").unwrap()" range: 283..285, elts: [], ctx: Load, + parenthesized: true, }, ), ], @@ -425,6 +428,7 @@ expression: "parse_suite(source, \"\").unwrap()" range: 312..314, elts: [], ctx: Load, + parenthesized: true, }, ), ], @@ -505,6 +509,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: false, }, ), ctx: Load, @@ -548,6 +553,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + 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 dec15e10e878d..2d6cde0597c6d 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 @@ -1,6 +1,6 @@ --- source: crates/ruff_python_parser/src/parser.rs -expression: "parse_suite(source, \"\").unwrap()" +expression: parse_suite(source).unwrap() --- [ With( @@ -275,6 +275,7 @@ expression: "parse_suite(source, \"\").unwrap()" range: 133..135, elts: [], ctx: Load, + parenthesized: true, }, ), optional_vars: None, @@ -301,6 +302,7 @@ expression: "parse_suite(source, \"\").unwrap()" range: 147..149, elts: [], ctx: Load, + parenthesized: true, }, ), optional_vars: Some( @@ -433,6 +435,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), optional_vars: Some( @@ -523,6 +526,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), optional_vars: Some( @@ -571,6 +575,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), optional_vars: None, @@ -611,6 +616,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), optional_vars: Some( @@ -667,6 +673,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), optional_vars: None, @@ -715,6 +722,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), optional_vars: Some( @@ -876,6 +884,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), optional_vars: None, @@ -943,6 +952,7 @@ expression: "parse_suite(source, \"\").unwrap()" ), ], ctx: Load, + parenthesized: true, }, ), optional_vars: Some(