diff --git a/crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_type_alias_annotation.py b/crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_type_alias_annotation.py new file mode 100644 index 0000000000000..56d06da2da8e9 --- /dev/null +++ b/crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_type_alias_annotation.py @@ -0,0 +1,2 @@ +a: type X = int +lambda: type X = int diff --git a/crates/ruff_python_parser/resources/invalid/statements/with/ambiguous_lpar_with_items.py b/crates/ruff_python_parser/resources/invalid/statements/with/ambiguous_lpar_with_items.py index a6f7ac163e5e7..49845c15c00d4 100644 --- a/crates/ruff_python_parser/resources/invalid/statements/with/ambiguous_lpar_with_items.py +++ b/crates/ruff_python_parser/resources/invalid/statements/with/ambiguous_lpar_with_items.py @@ -5,6 +5,7 @@ with (item1, item2), as f: ... with (item1, item2), item3,: ... with (*item): ... +with (*item) as f: ... with (item := 10 as f): ... with (item1, item2 := 10 as f): ... with (x for x in range(10), item): ... @@ -16,8 +17,16 @@ with (*x for x in iter, item): ... with (item1, *x for x in iter, item2): ... with (x as f, *y): ... +with (*x, y as f): ... with (x, yield y): ... with (x, yield y, z): ... with (x, yield from y): ... with (x as f, y) as f: ... -with (x for x in iter as y): ... \ No newline at end of file +with (x for x in iter as y): ... + +# The inner `(...)` is parsed as parenthesized expression +with ((item as f)): ... + +with (item as f), x: ... +with (item as f1) as f2: ... +with (item1 as f, item2 := 0): ... \ No newline at end of file diff --git a/crates/ruff_python_parser/resources/invalid/statements/with/unparenthesized_with_items.py b/crates/ruff_python_parser/resources/invalid/statements/with/unparenthesized_with_items.py new file mode 100644 index 0000000000000..dbe3f5229a96a --- /dev/null +++ b/crates/ruff_python_parser/resources/invalid/statements/with/unparenthesized_with_items.py @@ -0,0 +1,9 @@ +# For parenthesized with items test cases, refer to `./ambiguous_lpar_with_items.py` + +with item,: pass +with item as x,: pass +with *item: pass +with *item as x: pass +with *item1, item2 as f: pass +with item1 as f, *item2: pass +with item := 0 as f: pass \ No newline at end of file diff --git a/crates/ruff_python_parser/resources/valid/statement/ambiguous_lpar_with_items.py b/crates/ruff_python_parser/resources/valid/statement/ambiguous_lpar_with_items.py index e80bbdea47149..784e7b65c7cba 100644 --- a/crates/ruff_python_parser/resources/valid/statement/ambiguous_lpar_with_items.py +++ b/crates/ruff_python_parser/resources/valid/statement/ambiguous_lpar_with_items.py @@ -3,10 +3,6 @@ # parenthesize the with items or part of a parenthesized expression. It's not to test the # with statement itself. -# Simple unparenthesized cases -with item: ... -with item as f: ... - # The following sections basically separates between which node does the # start parenthesis belongs to. @@ -17,9 +13,12 @@ # - The range of the first with item shouldn't include the parenthesis. with (item): ... with (item,): ... # with a trailing comma +with (((item))): ... with (item1, item2): ... with (item1, item2,): ... # with a trailing comma +with ((item1), (item2), item3 as f, (item4)): ... with ((item1, item2), item3): ... +with ((x, y) as f): ... with (item1 as f1, item2 as f2): ... with (item1 as f1, item2 as f2,): ... # with a trailing comma with (item == 10,): ... @@ -27,6 +26,7 @@ with ((item := 10,)): ... with ((*item,)): ... with ((item1 := 10), item2): ... +with (item1 as f, (item2 := 10)): ... with (foo()): ... with (foo(),): ... with (foo() as f): ... @@ -46,6 +46,7 @@ # - The range of the first with item should include the parenthesis. with (item) as f: ... with (item := 10): ... +with (item := 10) as f: ... with ( item := 1 ): ... with (item1 := 42), item2: ... with (root + filename).read(): ... # Postfix expression @@ -57,7 +58,11 @@ with (1, 2, 3)[0]: ... # Postfix expression with (1, 2, 3)[0] as f: ... # Postfix expression with (item1), (item2): ... +with (open('a.py')), (open('b.py')): ... with (yield x): ... +with ((yield x)): ... +with (yield from x): ... +with ((yield from x)): ... with (yield x) as f: ... with (yield x,) as f: ... @@ -77,6 +82,7 @@ with (item1, item2 := 2, item3) as f: ... with (item,) as f: ... with (*item,): ... +with (*item,) as f: ... with (item1, item2) as f: ... with (item1, item2,) as f: ... with (item1, item2), item3: ... diff --git a/crates/ruff_python_parser/resources/valid/statement/with.py b/crates/ruff_python_parser/resources/valid/statement/with.py index e1b16ae47bf7d..7603c8539b518 100644 --- a/crates/ruff_python_parser/resources/valid/statement/with.py +++ b/crates/ruff_python_parser/resources/valid/statement/with.py @@ -1,2 +1,14 @@ -with 1 as x: - pass +# This file only contains unparenthesized with items. Refer to ./ambiguous_lpar_with_items.py +# for parenthesized with items test cases + +with item: ... +with item as f: ... +with item1, item2: ... +with item1 as f1, item2 as f2: ... + +with x if True else y: ... +with x if True else y as f: ... + +# Postfix expressions +with open() as f: ... +with open() as f.attr: ... \ No newline at end of file diff --git a/crates/ruff_python_parser/src/parser/statement.rs b/crates/ruff_python_parser/src/parser/statement.rs index cfe77c8323a80..ed057ac1e33b5 100644 --- a/crates/ruff_python_parser/src/parser/statement.rs +++ b/crates/ruff_python_parser/src/parser/statement.rs @@ -931,6 +931,10 @@ impl<'src> Parser<'src> { // x: yield a = 1 // x: yield from b = 1 // x: y := int = 1 + + // test_err ann_assign_stmt_type_alias_annotation + // a: type X = int + // lambda: type X = int let annotation = self.parse_conditional_expression_or_higher(AllowStarredExpression::No); let value = if self.eat(TokenKind::Equal) { diff --git a/crates/ruff_python_parser/src/parser/tests.rs b/crates/ruff_python_parser/src/parser/tests.rs index 2898e9f8f00fd..e8ad1ecc9cb61 100644 --- a/crates/ruff_python_parser/src/parser/tests.rs +++ b/crates/ruff_python_parser/src/parser/tests.rs @@ -1,6 +1,3 @@ -mod parser; -mod suite; - use crate::{lex, parse, parse_suite, parse_tokens, Mode}; #[test] diff --git a/crates/ruff_python_parser/src/parser/tests/parser.rs b/crates/ruff_python_parser/src/parser/tests/parser.rs deleted file mode 100644 index 2a222421420cc..0000000000000 --- a/crates/ruff_python_parser/src/parser/tests/parser.rs +++ /dev/null @@ -1,57 +0,0 @@ -#[cfg(test)] -mod tests { - - use crate::{ - lexer::lex, - parser::{Parser, Program}, - Mode, - }; - use insta::assert_debug_snapshot; - - fn parse(src: &str) -> Program { - let mode = Mode::Module; - let lexer = lex(src, mode); - let parser = Parser::new(src, mode, lexer.collect()); - let program = parser.parse_program(); - - assert_eq!(&program.parse_errors, &[]); - program - } - - #[test] - fn parse_with_stmt() { - assert_debug_snapshot!(parse( - " -with x: - ... -with x, y: - ... -with open() as f: - ... -with f() as x.attr: - pass -with x as X, y as Y, z as Z: - ... -with (x, z as Y, y,): - ... -with (a) as f: - ... -with ((a) as f, 1): - ... -with a: - yield a, b -with (yield 1): - ... -with (yield from 1): - ... -with (a := 1): - ... -with (open('bla.txt')), (open('bla.txt')): - pass -with (a := 1, x): - ... -with (p / 'new_file').open('wb'): ... -" - )); - } -} diff --git a/crates/ruff_python_parser/src/parser/tests/snapshots/ruff_python_parser__parser__tests__parser__tests__parse_with_stmt.snap b/crates/ruff_python_parser/src/parser/tests/snapshots/ruff_python_parser__parser__tests__parser__tests__parse_with_stmt.snap deleted file mode 100644 index 0be92fc4e0b2d..0000000000000 --- a/crates/ruff_python_parser/src/parser/tests/snapshots/ruff_python_parser__parser__tests__parser__tests__parse_with_stmt.snap +++ /dev/null @@ -1,843 +0,0 @@ ---- -source: crates/ruff_python_parser/src/parser/tests/parser.rs -expression: "parse(\"\nwith x:\n ...\nwith x, y:\n ...\nwith open() as f:\n ...\nwith f() as x.attr:\n pass\nwith x as X, y as Y, z as Z:\n ...\nwith (x, z as Y, y,):\n ...\nwith (a) as f:\n ...\nwith ((a) as f, 1):\n ...\nwith a:\n yield a, b\nwith (yield 1):\n ...\nwith (yield from 1):\n ...\nwith (a := 1):\n ...\nwith (open('bla.txt')), (open('bla.txt')):\n pass\nwith (a := 1, x):\n ...\nwith (p / 'new_file').open('wb'): ...\n\")" ---- -Program { - ast: Module( - ModModule { - range: 0..424, - body: [ - With( - StmtWith { - range: 1..16, - is_async: false, - items: [ - WithItem { - range: 6..7, - context_expr: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 13..16, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 13..16, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 17..35, - is_async: false, - items: [ - WithItem { - range: 22..23, - context_expr: Name( - ExprName { - range: 22..23, - id: "x", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 25..26, - context_expr: Name( - ExprName { - range: 25..26, - id: "y", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 32..35, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 32..35, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 36..61, - is_async: false, - items: [ - WithItem { - range: 41..52, - context_expr: Call( - ExprCall { - range: 41..47, - func: Name( - ExprName { - range: 41..45, - id: "open", - ctx: Load, - }, - ), - arguments: Arguments { - range: 45..47, - args: [], - keywords: [], - }, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 51..52, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 58..61, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 58..61, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 62..90, - is_async: false, - items: [ - WithItem { - range: 67..80, - context_expr: Call( - ExprCall { - range: 67..70, - func: Name( - ExprName { - range: 67..68, - id: "f", - ctx: Load, - }, - ), - arguments: Arguments { - range: 68..70, - args: [], - keywords: [], - }, - }, - ), - optional_vars: Some( - Attribute( - ExprAttribute { - range: 74..80, - value: Name( - ExprName { - range: 74..75, - id: "x", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 76..80, - }, - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 86..90, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 91..127, - is_async: false, - items: [ - WithItem { - range: 96..102, - context_expr: Name( - ExprName { - range: 96..97, - id: "x", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 101..102, - id: "X", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 104..110, - context_expr: Name( - ExprName { - range: 104..105, - id: "y", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 109..110, - id: "Y", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 112..118, - context_expr: Name( - ExprName { - range: 112..113, - id: "z", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 117..118, - id: "Z", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 124..127, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 124..127, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 128..157, - is_async: false, - items: [ - WithItem { - range: 134..135, - context_expr: Name( - ExprName { - range: 134..135, - id: "x", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 137..143, - context_expr: Name( - ExprName { - range: 137..138, - id: "z", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 142..143, - id: "Y", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 145..146, - context_expr: Name( - ExprName { - range: 145..146, - id: "y", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 154..157, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 154..157, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 158..180, - is_async: false, - items: [ - WithItem { - range: 163..171, - context_expr: Name( - ExprName { - range: 164..165, - id: "a", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 170..171, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 177..180, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 177..180, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 181..208, - is_async: false, - items: [ - WithItem { - range: 187..195, - context_expr: Name( - ExprName { - range: 188..189, - id: "a", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 194..195, - id: "f", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 197..198, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 197..198, - value: Int( - 1, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 205..208, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 205..208, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 209..231, - is_async: false, - items: [ - WithItem { - range: 214..215, - context_expr: Name( - ExprName { - range: 214..215, - id: "a", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 221..231, - value: Yield( - ExprYield { - range: 221..231, - value: Some( - Tuple( - ExprTuple { - range: 227..231, - elts: [ - Name( - ExprName { - range: 227..228, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 230..231, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 232..255, - is_async: false, - items: [ - WithItem { - range: 237..246, - context_expr: Yield( - ExprYield { - range: 238..245, - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 244..245, - value: Int( - 1, - ), - }, - ), - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 252..255, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 252..255, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 256..284, - is_async: false, - items: [ - WithItem { - range: 261..275, - context_expr: YieldFrom( - ExprYieldFrom { - range: 262..274, - value: NumberLiteral( - ExprNumberLiteral { - range: 273..274, - value: Int( - 1, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 281..284, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 281..284, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 285..307, - is_async: false, - items: [ - WithItem { - range: 290..298, - context_expr: Named( - ExprNamed { - range: 291..297, - target: Name( - ExprName { - range: 291..292, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 296..297, - value: Int( - 1, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 304..307, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 304..307, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 308..359, - is_async: false, - items: [ - WithItem { - range: 313..330, - context_expr: Call( - ExprCall { - range: 314..329, - func: Name( - ExprName { - range: 314..318, - id: "open", - ctx: Load, - }, - ), - arguments: Arguments { - range: 318..329, - args: [ - StringLiteral( - ExprStringLiteral { - range: 319..328, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 319..328, - value: "bla.txt", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - optional_vars: None, - }, - WithItem { - range: 332..349, - context_expr: Call( - ExprCall { - range: 333..348, - func: Name( - ExprName { - range: 333..337, - id: "open", - ctx: Load, - }, - ), - arguments: Arguments { - range: 337..348, - args: [ - StringLiteral( - ExprStringLiteral { - range: 338..347, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 338..347, - value: "bla.txt", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 355..359, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 360..385, - is_async: false, - items: [ - WithItem { - range: 365..376, - context_expr: Tuple( - ExprTuple { - range: 365..376, - elts: [ - Named( - ExprNamed { - range: 366..372, - target: Name( - ExprName { - range: 366..367, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 371..372, - value: Int( - 1, - ), - }, - ), - }, - ), - Name( - ExprName { - range: 374..375, - id: "x", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 382..385, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 382..385, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 386..423, - is_async: false, - items: [ - WithItem { - range: 391..418, - context_expr: Call( - ExprCall { - range: 391..418, - func: Attribute( - ExprAttribute { - range: 391..412, - value: BinOp( - ExprBinOp { - range: 392..406, - left: Name( - ExprName { - range: 392..393, - id: "p", - ctx: Load, - }, - ), - op: Div, - right: StringLiteral( - ExprStringLiteral { - range: 396..406, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 396..406, - value: "new_file", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - attr: Identifier { - id: "open", - range: 408..412, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 412..418, - args: [ - StringLiteral( - ExprStringLiteral { - range: 413..417, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 413..417, - value: "wb", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 420..423, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 420..423, - }, - ), - }, - ), - ], - }, - ), - ], - }, - ), - parse_errors: [], -} diff --git a/crates/ruff_python_parser/src/parser/tests/snapshots/ruff_python_parser__parser__tests__suite__tests__parenthesized_with_statement.snap b/crates/ruff_python_parser/src/parser/tests/snapshots/ruff_python_parser__parser__tests__suite__tests__parenthesized_with_statement.snap deleted file mode 100644 index cc28e38a4e6f2..0000000000000 --- a/crates/ruff_python_parser/src/parser/tests/snapshots/ruff_python_parser__parser__tests__suite__tests__parenthesized_with_statement.snap +++ /dev/null @@ -1,678 +0,0 @@ ---- -source: crates/ruff_python_parser/src/parser/tests/suite.rs -expression: parse_suite(source).unwrap() ---- -[ - With( - StmtWith { - range: 0..21, - is_async: false, - items: [ - WithItem { - range: 6..9, - context_expr: Name( - ExprName { - range: 7..8, - id: "a", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 11..14, - context_expr: Name( - ExprName { - range: 12..13, - id: "b", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 17..21, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 22..56, - is_async: false, - items: [ - WithItem { - range: 28..31, - context_expr: Name( - ExprName { - range: 29..30, - id: "a", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 33..36, - context_expr: Name( - ExprName { - range: 34..35, - id: "b", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 38..44, - context_expr: Name( - ExprName { - range: 38..39, - id: "c", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 43..44, - id: "d", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 46..49, - context_expr: Name( - ExprName { - range: 47..48, - id: "e", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 52..56, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 57..74, - is_async: false, - items: [ - WithItem { - range: 63..64, - context_expr: Name( - ExprName { - range: 63..64, - id: "a", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 66..67, - context_expr: Name( - ExprName { - range: 66..67, - id: "b", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 70..74, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 75..97, - is_async: false, - items: [ - WithItem { - range: 80..91, - context_expr: Tuple( - ExprTuple { - range: 80..86, - elts: [ - Name( - ExprName { - range: 81..82, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 84..85, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 90..91, - id: "c", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 93..97, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 98..122, - is_async: false, - items: [ - WithItem { - range: 104..115, - context_expr: Tuple( - ExprTuple { - range: 104..110, - elts: [ - Name( - ExprName { - range: 105..106, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 108..109, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 114..115, - id: "c", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 118..122, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 123..142, - is_async: false, - items: [ - WithItem { - range: 129..135, - context_expr: Name( - ExprName { - range: 129..130, - id: "a", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 134..135, - id: "b", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 138..142, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 143..157, - is_async: false, - items: [ - WithItem { - range: 149..150, - context_expr: Name( - ExprName { - range: 149..150, - id: "a", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 153..157, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 158..177, - is_async: false, - items: [ - WithItem { - range: 164..170, - context_expr: Named( - ExprNamed { - range: 164..170, - target: Name( - ExprName { - range: 164..165, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 169..170, - value: Int( - 0, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 173..177, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 178..202, - is_async: false, - items: [ - WithItem { - range: 183..196, - context_expr: Named( - ExprNamed { - range: 184..190, - target: Name( - ExprName { - range: 184..185, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 189..190, - value: Int( - 0, - ), - }, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 195..196, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 198..202, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 203..219, - is_async: false, - items: [ - WithItem { - range: 209..212, - context_expr: Name( - ExprName { - range: 210..211, - id: "a", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 215..219, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 220..241, - is_async: false, - items: [ - WithItem { - range: 226..234, - context_expr: Named( - ExprNamed { - range: 227..233, - target: Name( - ExprName { - range: 227..228, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 232..233, - value: Int( - 0, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 237..241, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 242..271, - is_async: false, - items: [ - WithItem { - range: 248..254, - context_expr: Name( - ExprName { - range: 248..249, - id: "a", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 253..254, - id: "b", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 256..264, - context_expr: Named( - ExprNamed { - range: 257..263, - target: Name( - ExprName { - range: 257..258, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 262..263, - value: Int( - 0, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 267..271, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 272..296, - is_async: false, - items: [ - WithItem { - range: 278..279, - context_expr: Name( - ExprName { - range: 278..279, - id: "a", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 281..289, - context_expr: Named( - ExprNamed { - range: 282..288, - target: Name( - ExprName { - range: 282..283, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 287..288, - value: Int( - 0, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 292..296, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 297..315, - is_async: false, - items: [ - WithItem { - range: 303..308, - context_expr: Yield( - ExprYield { - range: 303..308, - value: None, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 311..315, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 316..341, - is_async: false, - items: [ - WithItem { - range: 322..334, - context_expr: YieldFrom( - ExprYieldFrom { - range: 322..334, - value: Name( - ExprName { - range: 333..334, - id: "a", - ctx: Load, - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 337..341, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 342..362, - is_async: false, - items: [ - WithItem { - range: 348..355, - context_expr: Yield( - ExprYield { - range: 349..354, - value: None, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 358..362, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 363..390, - is_async: false, - items: [ - WithItem { - range: 369..383, - context_expr: YieldFrom( - ExprYieldFrom { - range: 370..382, - value: Name( - ExprName { - range: 381..382, - id: "a", - ctx: Load, - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 386..390, - }, - ), - ], - }, - ), -] diff --git a/crates/ruff_python_parser/src/parser/tests/snapshots/ruff_python_parser__parser__tests__suite__tests__with_statement.snap b/crates/ruff_python_parser/src/parser/tests/snapshots/ruff_python_parser__parser__tests__suite__tests__with_statement.snap deleted file mode 100644 index 1e87c7c07cf50..0000000000000 --- a/crates/ruff_python_parser/src/parser/tests/snapshots/ruff_python_parser__parser__tests__suite__tests__with_statement.snap +++ /dev/null @@ -1,1158 +0,0 @@ ---- -source: crates/ruff_python_parser/src/parser/tests/suite.rs -expression: parse_suite(source).unwrap() ---- -[ - With( - StmtWith { - range: 0..12, - is_async: false, - items: [ - WithItem { - range: 5..6, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 0, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 8..12, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 13..30, - is_async: false, - items: [ - WithItem { - range: 18..24, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 18..19, - value: Int( - 0, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 23..24, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 26..30, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 31..46, - is_async: false, - items: [ - WithItem { - range: 36..37, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 36..37, - value: Int( - 0, - ), - }, - ), - optional_vars: None, - }, - WithItem { - range: 39..40, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 39..40, - value: Int( - 1, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 42..46, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 47..72, - is_async: false, - items: [ - WithItem { - range: 52..58, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 52..53, - value: Int( - 0, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 57..58, - id: "x", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 60..66, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 60..61, - value: Int( - 1, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 65..66, - id: "y", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 68..72, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 73..97, - is_async: false, - items: [ - WithItem { - range: 78..91, - context_expr: If( - ExprIf { - range: 78..91, - test: NumberLiteral( - ExprNumberLiteral { - range: 83..84, - value: Int( - 1, - ), - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 78..79, - value: Int( - 0, - ), - }, - ), - orelse: NumberLiteral( - ExprNumberLiteral { - range: 90..91, - value: Int( - 2, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 93..97, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 98..127, - is_async: false, - items: [ - WithItem { - range: 103..121, - context_expr: If( - ExprIf { - range: 103..116, - test: NumberLiteral( - ExprNumberLiteral { - range: 108..109, - value: Int( - 1, - ), - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 103..104, - value: Int( - 0, - ), - }, - ), - orelse: NumberLiteral( - ExprNumberLiteral { - range: 115..116, - value: Int( - 2, - ), - }, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 120..121, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 123..127, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 128..141, - is_async: false, - items: [ - WithItem { - range: 133..135, - context_expr: Tuple( - ExprTuple { - range: 133..135, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 137..141, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 142..160, - is_async: false, - items: [ - WithItem { - range: 147..154, - context_expr: Tuple( - ExprTuple { - range: 147..149, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 153..154, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 156..160, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 161..175, - is_async: false, - items: [ - WithItem { - range: 167..168, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 167..168, - value: Int( - 0, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 171..175, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 176..195, - is_async: false, - items: [ - WithItem { - range: 181..189, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 182..183, - value: Int( - 0, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 188..189, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 191..195, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 196..211, - is_async: false, - items: [ - WithItem { - range: 202..203, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 202..203, - value: Int( - 0, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 207..211, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 212..232, - is_async: false, - items: [ - WithItem { - range: 217..226, - context_expr: Tuple( - ExprTuple { - range: 217..221, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 218..219, - value: Int( - 0, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 225..226, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 228..232, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 233..250, - is_async: false, - items: [ - WithItem { - range: 239..240, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 239..240, - value: Int( - 0, - ), - }, - ), - optional_vars: None, - }, - WithItem { - range: 242..243, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 242..243, - value: Int( - 1, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 246..250, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 251..273, - is_async: false, - items: [ - WithItem { - range: 256..267, - context_expr: Tuple( - ExprTuple { - range: 256..262, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 257..258, - value: Int( - 0, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 260..261, - value: Int( - 1, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 266..267, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 269..273, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 274..290, - is_async: false, - items: [ - WithItem { - range: 279..284, - context_expr: Tuple( - ExprTuple { - range: 279..284, - elts: [ - Starred( - ExprStarred { - range: 280..282, - value: Name( - ExprName { - range: 281..282, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 286..290, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 291..312, - is_async: false, - items: [ - WithItem { - range: 296..306, - context_expr: Tuple( - ExprTuple { - range: 296..301, - elts: [ - Starred( - ExprStarred { - range: 297..299, - value: Name( - ExprName { - range: 298..299, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 305..306, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 308..312, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 313..331, - is_async: false, - items: [ - WithItem { - range: 318..325, - context_expr: Tuple( - ExprTuple { - range: 318..325, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 319..320, - value: Int( - 0, - ), - }, - ), - Starred( - ExprStarred { - range: 322..324, - value: Name( - ExprName { - range: 323..324, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 327..331, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 332..355, - is_async: false, - items: [ - WithItem { - range: 337..349, - context_expr: Tuple( - ExprTuple { - range: 337..344, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 338..339, - value: Int( - 0, - ), - }, - ), - Starred( - ExprStarred { - range: 341..343, - value: Name( - ExprName { - range: 342..343, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 348..349, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 351..355, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 356..375, - is_async: false, - items: [ - WithItem { - range: 362..368, - context_expr: Named( - ExprNamed { - range: 362..368, - target: Name( - ExprName { - range: 362..363, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 367..368, - value: Int( - 0, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 371..375, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 376..400, - is_async: false, - items: [ - WithItem { - range: 381..394, - context_expr: Named( - ExprNamed { - range: 382..388, - target: Name( - ExprName { - range: 382..383, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 387..388, - value: Int( - 0, - ), - }, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 393..394, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 396..400, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 401..428, - is_async: false, - items: [ - WithItem { - range: 406..422, - context_expr: Tuple( - ExprTuple { - range: 406..422, - elts: [ - Named( - ExprNamed { - range: 407..413, - target: Name( - ExprName { - range: 407..408, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 412..413, - value: Int( - 0, - ), - }, - ), - }, - ), - Named( - ExprNamed { - range: 415..421, - target: Name( - ExprName { - range: 415..416, - id: "b", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 420..421, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 424..428, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 429..461, - is_async: false, - items: [ - WithItem { - range: 434..455, - context_expr: Tuple( - ExprTuple { - range: 434..450, - elts: [ - Named( - ExprNamed { - range: 435..441, - target: Name( - ExprName { - range: 435..436, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 440..441, - value: Int( - 0, - ), - }, - ), - }, - ), - Named( - ExprNamed { - range: 443..449, - target: Name( - ExprName { - range: 443..444, - id: "b", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 448..449, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 454..455, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 457..461, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 462..481, - is_async: false, - items: [ - WithItem { - range: 468..474, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 468..469, - value: Int( - 0, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 473..474, - id: "a", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 477..481, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 482..502, - is_async: false, - items: [ - WithItem { - range: 488..494, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 488..489, - value: Int( - 0, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 493..494, - id: "a", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 498..502, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 503..530, - is_async: false, - items: [ - WithItem { - range: 509..515, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 509..510, - value: Int( - 0, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 514..515, - id: "a", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 517..523, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 517..518, - value: Int( - 1, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 522..523, - id: "b", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 526..530, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 531..559, - is_async: false, - items: [ - WithItem { - range: 537..543, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 537..538, - value: Int( - 0, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 542..543, - id: "a", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 545..551, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 545..546, - value: Int( - 1, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 550..551, - id: "b", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 555..559, - }, - ), - ], - }, - ), -] diff --git a/crates/ruff_python_parser/src/parser/tests/suite.rs b/crates/ruff_python_parser/src/parser/tests/suite.rs deleted file mode 100644 index d928f19ffd431..0000000000000 --- a/crates/ruff_python_parser/src/parser/tests/suite.rs +++ /dev/null @@ -1,91 +0,0 @@ -#[cfg(test)] -mod tests { - use crate::parse_suite; - - #[test] - fn test_with_statement() { - let source = "\ -with 0: pass -with 0 as x: pass -with 0, 1: pass -with 0 as x, 1 as y: pass -with 0 if 1 else 2: pass -with 0 if 1 else 2 as x: pass -with (): pass -with () as x: pass -with (0): pass -with (0) as x: pass -with (0,): pass -with (0,) as x: pass -with (0, 1): pass -with (0, 1) as x: pass -with (*a,): pass -with (*a,) as x: pass -with (0, *a): pass -with (0, *a) as x: pass -with (a := 0): pass -with (a := 0) as x: pass -with (a := 0, b := 1): pass -with (a := 0, b := 1) as x: pass -with (0 as a): pass -with (0 as a,): pass -with (0 as a, 1 as b): pass -with (0 as a, 1 as b,): pass -"; - insta::assert_debug_snapshot!(parse_suite(source).unwrap()); - } - - #[test] - fn test_parenthesized_with_statement() { - let source = "\ -with ((a), (b)): pass -with ((a), (b), c as d, (e)): pass -with (a, b): pass -with (a, b) as c: pass -with ((a, b) as c): pass -with (a as b): pass -with (a): pass -with (a := 0): pass -with (a := 0) as x: pass -with ((a)): pass -with ((a := 0)): pass -with (a as b, (a := 0)): pass -with (a, (a := 0)): pass -with (yield): pass -with (yield from a): pass -with ((yield)): pass -with ((yield from a)): pass -"; - insta::assert_debug_snapshot!(parse_suite(source).unwrap()); - } - - #[test] - fn test_with_statement_invalid() { - for source in [ - "with 0,: pass", - "with 0 as x,: pass", - "with *a: pass", - "with *a as x: pass", - "with (*a): pass", - "with (*a) as x: pass", - "with *a, 0 as x: pass", - "with (*a, 0 as x): pass", - "with 0 as x, *a: pass", - "with (0 as x, *a): pass", - "with (0 as x) as y: pass", - "with (0 as x), 1: pass", - "with ((0 as x)): pass", - "with a := 0 as x: pass", - "with (a := 0 as x): pass", - ] { - assert!(parse_suite(source).is_err()); - } - } - - #[test] - fn test_invalid_type() { - // TODO(dhruvmanila): Check error recovery for these cases - assert!(parse_suite("a: type X = int").is_err()); - assert!(parse_suite("lambda: type X = int").is_err()); - } -} diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap new file mode 100644 index 0000000000000..a98790971d0d3 --- /dev/null +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap @@ -0,0 +1,122 @@ +--- +source: crates/ruff_python_parser/tests/fixtures.rs +input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_type_alias_annotation.py +--- +## AST + +``` +Module( + ModModule { + range: 0..37, + body: [ + AnnAssign( + StmtAnnAssign { + range: 0..2, + target: Name( + ExprName { + range: 0..1, + id: "a", + ctx: Store, + }, + ), + annotation: Name( + ExprName { + range: 2..2, + id: "", + ctx: Invalid, + }, + ), + value: None, + simple: true, + }, + ), + TypeAlias( + StmtTypeAlias { + range: 3..15, + name: Name( + ExprName { + range: 8..9, + id: "X", + ctx: Store, + }, + ), + type_params: None, + value: Name( + ExprName { + range: 12..15, + id: "int", + ctx: Load, + }, + ), + }, + ), + Expr( + StmtExpr { + range: 16..23, + value: Lambda( + ExprLambda { + range: 16..23, + parameters: None, + body: Name( + ExprName { + range: 23..23, + id: "", + ctx: Invalid, + }, + ), + }, + ), + }, + ), + TypeAlias( + StmtTypeAlias { + range: 24..36, + name: Name( + ExprName { + range: 29..30, + id: "X", + ctx: Store, + }, + ), + type_params: None, + value: Name( + ExprName { + range: 33..36, + id: "int", + ctx: Load, + }, + ), + }, + ), + ], + }, +) +``` +## Errors + + | +1 | a: type X = int + | ^^^^ Syntax Error: Expected an expression +2 | lambda: type X = int + | + + + | +1 | a: type X = int + | ^^^^^^^ Syntax Error: use `;` to separate simple statements +2 | lambda: type X = int + | + + + | +1 | a: type X = int +2 | lambda: type X = int + | ^^^^ Syntax Error: Expected an expression + | + + + | +1 | a: type X = int +2 | lambda: type X = int + | ^^^^^^^^^^^^ Syntax Error: use `;` to separate simple statements + | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap index 0ff48b22f02de..a88cc8eb9538b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap @@ -7,7 +7,7 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/with/ambiguou ``` Module( ModModule { - range: 0..731, + range: 0..950, body: [ With( StmtWith { @@ -211,24 +211,69 @@ Module( ), With( StmtWith { - range: 271..298, + range: 271..293, is_async: false, items: [ WithItem { - range: 277..292, + range: 276..288, + context_expr: Starred( + ExprStarred { + range: 277..282, + value: Name( + ExprName { + range: 278..282, + id: "item", + ctx: Load, + }, + ), + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 287..288, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Expr( + StmtExpr { + range: 290..293, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 290..293, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 294..321, + is_async: false, + items: [ + WithItem { + range: 300..315, context_expr: Named( ExprNamed { - range: 277..287, + range: 300..310, target: Name( ExprName { - range: 277..281, + range: 300..304, id: "item", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 285..287, + range: 308..310, value: Int( 10, ), @@ -239,7 +284,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 291..292, + range: 314..315, id: "f", ctx: Store, }, @@ -250,10 +295,10 @@ Module( body: [ Expr( StmtExpr { - range: 295..298, + range: 318..321, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 295..298, + range: 318..321, }, ), }, @@ -263,14 +308,14 @@ Module( ), With( StmtWith { - range: 299..334, + range: 322..357, is_async: false, items: [ WithItem { - range: 305..310, + range: 328..333, context_expr: Name( ExprName { - range: 305..310, + range: 328..333, id: "item1", ctx: Load, }, @@ -278,20 +323,20 @@ Module( optional_vars: None, }, WithItem { - range: 312..328, + range: 335..351, context_expr: Named( ExprNamed { - range: 312..323, + range: 335..346, target: Name( ExprName { - range: 312..317, + range: 335..340, id: "item2", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 321..323, + range: 344..346, value: Int( 10, ), @@ -302,7 +347,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 327..328, + range: 350..351, id: "f", ctx: Store, }, @@ -313,10 +358,10 @@ Module( body: [ Expr( StmtExpr { - range: 331..334, + range: 354..357, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 331..334, + range: 354..357, }, ), }, @@ -326,47 +371,47 @@ Module( ), With( StmtWith { - range: 335..373, + range: 358..396, is_async: false, items: [ WithItem { - range: 341..361, + range: 364..384, context_expr: Generator( ExprGenerator { - range: 341..361, + range: 364..384, elt: Name( ExprName { - range: 341..342, + range: 364..365, id: "x", ctx: Load, }, ), generators: [ Comprehension { - range: 343..361, + range: 366..384, target: Name( ExprName { - range: 347..348, + range: 370..371, id: "x", ctx: Store, }, ), iter: Call( ExprCall { - range: 352..361, + range: 375..384, func: Name( ExprName { - range: 352..357, + range: 375..380, id: "range", ctx: Load, }, ), arguments: Arguments { - range: 357..361, + range: 380..384, args: [ NumberLiteral( ExprNumberLiteral { - range: 358..360, + range: 381..383, value: Int( 10, ), @@ -387,10 +432,10 @@ Module( optional_vars: None, }, WithItem { - range: 363..367, + range: 386..390, context_expr: Name( ExprName { - range: 363..367, + range: 386..390, id: "item", ctx: Load, }, @@ -401,10 +446,10 @@ Module( body: [ Expr( StmtExpr { - range: 370..373, + range: 393..396, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 370..373, + range: 393..396, }, ), }, @@ -414,14 +459,14 @@ Module( ), With( StmtWith { - range: 374..412, + range: 397..435, is_async: false, items: [ WithItem { - range: 380..384, + range: 403..407, context_expr: Name( ExprName { - range: 380..384, + range: 403..407, id: "item", ctx: Load, }, @@ -429,43 +474,43 @@ Module( optional_vars: None, }, WithItem { - range: 386..406, + range: 409..429, context_expr: Generator( ExprGenerator { - range: 386..406, + range: 409..429, elt: Name( ExprName { - range: 386..387, + range: 409..410, id: "x", ctx: Load, }, ), generators: [ Comprehension { - range: 388..406, + range: 411..429, target: Name( ExprName { - range: 392..393, + range: 415..416, id: "x", ctx: Store, }, ), iter: Call( ExprCall { - range: 397..406, + range: 420..429, func: Name( ExprName { - range: 397..402, + range: 420..425, id: "range", ctx: Load, }, ), arguments: Arguments { - range: 402..406, + range: 425..429, args: [ NumberLiteral( ExprNumberLiteral { - range: 403..405, + range: 426..428, value: Int( 10, ), @@ -489,10 +534,10 @@ Module( body: [ Expr( StmtExpr { - range: 409..412, + range: 432..435, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 409..412, + range: 432..435, }, ), }, @@ -502,17 +547,17 @@ Module( ), With( StmtWith { - range: 473..492, + range: 496..515, is_async: false, items: [ WithItem { - range: 479..486, + range: 502..509, context_expr: Starred( ExprStarred { - range: 480..485, + range: 503..508, value: Name( ExprName { - range: 481..485, + range: 504..508, id: "item", ctx: Load, }, @@ -526,10 +571,10 @@ Module( body: [ Expr( StmtExpr { - range: 489..492, + range: 512..515, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 489..492, + range: 512..515, }, ), }, @@ -539,20 +584,20 @@ Module( ), With( StmtWith { - range: 494..528, + range: 517..551, is_async: false, items: [ WithItem { - range: 500..516, + range: 523..539, context_expr: Generator( ExprGenerator { - range: 500..516, + range: 523..539, elt: Starred( ExprStarred { - range: 500..502, + range: 523..525, value: Name( ExprName { - range: 501..502, + range: 524..525, id: "x", ctx: Load, }, @@ -562,17 +607,17 @@ Module( ), generators: [ Comprehension { - range: 503..516, + range: 526..539, target: Name( ExprName { - range: 507..508, + range: 530..531, id: "x", ctx: Store, }, ), iter: Name( ExprName { - range: 512..516, + range: 535..539, id: "iter", ctx: Load, }, @@ -587,10 +632,10 @@ Module( optional_vars: None, }, WithItem { - range: 518..522, + range: 541..545, context_expr: Name( ExprName { - range: 518..522, + range: 541..545, id: "item", ctx: Load, }, @@ -601,10 +646,10 @@ Module( body: [ Expr( StmtExpr { - range: 525..528, + range: 548..551, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 525..528, + range: 548..551, }, ), }, @@ -614,14 +659,14 @@ Module( ), With( StmtWith { - range: 529..571, + range: 552..594, is_async: false, items: [ WithItem { - range: 535..540, + range: 558..563, context_expr: Name( ExprName { - range: 535..540, + range: 558..563, id: "item1", ctx: Load, }, @@ -629,16 +674,16 @@ Module( optional_vars: None, }, WithItem { - range: 542..558, + range: 565..581, context_expr: Generator( ExprGenerator { - range: 542..558, + range: 565..581, elt: Starred( ExprStarred { - range: 542..544, + range: 565..567, value: Name( ExprName { - range: 543..544, + range: 566..567, id: "x", ctx: Load, }, @@ -648,17 +693,17 @@ Module( ), generators: [ Comprehension { - range: 545..558, + range: 568..581, target: Name( ExprName { - range: 549..550, + range: 572..573, id: "x", ctx: Store, }, ), iter: Name( ExprName { - range: 554..558, + range: 577..581, id: "iter", ctx: Load, }, @@ -673,10 +718,10 @@ Module( optional_vars: None, }, WithItem { - range: 560..565, + range: 583..588, context_expr: Name( ExprName { - range: 560..565, + range: 583..588, id: "item2", ctx: Load, }, @@ -687,10 +732,10 @@ Module( body: [ Expr( StmtExpr { - range: 568..571, + range: 591..594, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 568..571, + range: 591..594, }, ), }, @@ -700,14 +745,14 @@ Module( ), With( StmtWith { - range: 572..594, + range: 595..617, is_async: false, items: [ WithItem { - range: 578..584, + range: 601..607, context_expr: Name( ExprName { - range: 578..579, + range: 601..602, id: "x", ctx: Load, }, @@ -715,7 +760,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 583..584, + range: 606..607, id: "f", ctx: Store, }, @@ -723,13 +768,13 @@ Module( ), }, WithItem { - range: 586..588, + range: 609..611, context_expr: Starred( ExprStarred { - range: 586..588, + range: 609..611, value: Name( ExprName { - range: 587..588, + range: 610..611, id: "y", ctx: Load, }, @@ -743,10 +788,10 @@ Module( body: [ Expr( StmtExpr { - range: 591..594, + range: 614..617, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 591..594, + range: 614..617, }, ), }, @@ -756,29 +801,85 @@ Module( ), With( StmtWith { - range: 595..617, + range: 618..640, + is_async: false, + items: [ + WithItem { + range: 624..626, + context_expr: Starred( + ExprStarred { + range: 624..626, + value: Name( + ExprName { + range: 625..626, + id: "x", + ctx: Load, + }, + ), + ctx: Load, + }, + ), + optional_vars: None, + }, + WithItem { + range: 628..634, + context_expr: Name( + ExprName { + range: 628..629, + id: "y", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 633..634, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Expr( + StmtExpr { + range: 637..640, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 637..640, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 641..663, is_async: false, items: [ WithItem { - range: 600..612, + range: 646..658, context_expr: Tuple( ExprTuple { - range: 600..612, + range: 646..658, elts: [ Name( ExprName { - range: 601..602, + range: 647..648, id: "x", ctx: Load, }, ), Yield( ExprYield { - range: 604..611, + range: 650..657, value: Some( Name( ExprName { - range: 610..611, + range: 656..657, id: "y", ctx: Load, }, @@ -797,10 +898,10 @@ Module( body: [ Expr( StmtExpr { - range: 614..617, + range: 660..663, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 614..617, + range: 660..663, }, ), }, @@ -810,40 +911,40 @@ Module( ), With( StmtWith { - range: 618..643, + range: 664..689, is_async: false, items: [ WithItem { - range: 623..638, + range: 669..684, context_expr: Tuple( ExprTuple { - range: 623..638, + range: 669..684, elts: [ Name( ExprName { - range: 624..625, + range: 670..671, id: "x", ctx: Load, }, ), Yield( ExprYield { - range: 627..637, + range: 673..683, value: Some( Tuple( ExprTuple { - range: 633..637, + range: 679..683, elts: [ Name( ExprName { - range: 633..634, + range: 679..680, id: "y", ctx: Load, }, ), Name( ExprName { - range: 636..637, + range: 682..683, id: "z", ctx: Load, }, @@ -867,10 +968,10 @@ Module( body: [ Expr( StmtExpr { - range: 640..643, + range: 686..689, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 640..643, + range: 686..689, }, ), }, @@ -880,28 +981,28 @@ Module( ), With( StmtWith { - range: 644..671, + range: 690..717, is_async: false, items: [ WithItem { - range: 649..666, + range: 695..712, context_expr: Tuple( ExprTuple { - range: 649..666, + range: 695..712, elts: [ Name( ExprName { - range: 650..651, + range: 696..697, id: "x", ctx: Load, }, ), YieldFrom( ExprYieldFrom { - range: 653..665, + range: 699..711, value: Name( ExprName { - range: 664..665, + range: 710..711, id: "y", ctx: Load, }, @@ -919,10 +1020,10 @@ Module( body: [ Expr( StmtExpr { - range: 668..671, + range: 714..717, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 668..671, + range: 714..717, }, ), }, @@ -932,14 +1033,14 @@ Module( ), With( StmtWith { - range: 672..688, + range: 718..734, is_async: false, items: [ WithItem { - range: 678..684, + range: 724..730, context_expr: Name( ExprName { - range: 678..679, + range: 724..725, id: "x", ctx: Load, }, @@ -947,7 +1048,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 683..684, + range: 729..730, id: "f", ctx: Store, }, @@ -955,10 +1056,10 @@ Module( ), }, WithItem { - range: 686..687, + range: 732..733, context_expr: Name( ExprName { - range: 686..687, + range: 732..733, id: "y", ctx: Load, }, @@ -971,17 +1072,17 @@ Module( ), AnnAssign( StmtAnnAssign { - range: 692..698, + range: 738..744, target: Name( ExprName { - range: 692..693, + range: 738..739, id: "f", ctx: Store, }, ), annotation: EllipsisLiteral( ExprEllipsisLiteral { - range: 695..698, + range: 741..744, }, ), value: None, @@ -990,34 +1091,34 @@ Module( ), With( StmtWith { - range: 699..731, + range: 745..777, is_async: false, items: [ WithItem { - range: 705..725, + range: 751..771, context_expr: Generator( ExprGenerator { - range: 705..720, + range: 751..766, elt: Name( ExprName { - range: 705..706, + range: 751..752, id: "x", ctx: Load, }, ), generators: [ Comprehension { - range: 707..720, + range: 753..766, target: Name( ExprName { - range: 711..712, + range: 757..758, id: "x", ctx: Store, }, ), iter: Name( ExprName { - range: 716..720, + range: 762..766, id: "iter", ctx: Load, }, @@ -1032,7 +1133,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 724..725, + range: 770..771, id: "y", ctx: Store, }, @@ -1043,10 +1144,205 @@ Module( body: [ Expr( StmtExpr { - range: 728..731, + range: 774..777, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 728..731, + range: 774..777, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 837..854, + is_async: false, + items: [ + WithItem { + range: 843..853, + context_expr: Name( + ExprName { + range: 844..848, + id: "item", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 852..853, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [], + }, + ), + Expr( + StmtExpr { + range: 857..860, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 857..860, + }, + ), + }, + ), + With( + StmtWith { + range: 862..878, + is_async: false, + items: [ + WithItem { + range: 868..877, + context_expr: Name( + ExprName { + range: 868..872, + id: "item", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 876..877, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [], + }, + ), + AnnAssign( + StmtAnnAssign { + range: 880..886, + target: Name( + ExprName { + range: 880..881, + id: "x", + ctx: Store, + }, + ), + annotation: EllipsisLiteral( + ExprEllipsisLiteral { + range: 883..886, + }, + ), + value: None, + simple: true, + }, + ), + With( + StmtWith { + range: 887..904, + is_async: false, + items: [ + WithItem { + range: 893..903, + context_expr: Name( + ExprName { + range: 893..897, + id: "item", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 901..903, + id: "f1", + ctx: Store, + }, + ), + ), + }, + ], + body: [], + }, + ), + AnnAssign( + StmtAnnAssign { + range: 908..915, + target: Name( + ExprName { + range: 908..910, + id: "f2", + ctx: Store, + }, + ), + annotation: EllipsisLiteral( + ExprEllipsisLiteral { + range: 912..915, + }, + ), + value: None, + simple: true, + }, + ), + With( + StmtWith { + range: 916..950, + is_async: false, + items: [ + WithItem { + range: 922..932, + context_expr: Name( + ExprName { + range: 922..927, + id: "item1", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 931..932, + id: "f", + ctx: Store, + }, + ), + ), + }, + WithItem { + range: 934..944, + context_expr: Named( + ExprNamed { + range: 934..944, + target: Name( + ExprName { + range: 934..939, + id: "item2", + ctx: Store, + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 943..944, + value: Int( + 0, + ), + }, + ), + }, + ), + optional_vars: None, + }, + ], + body: [ + Expr( + StmtExpr { + range: 947..950, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 947..950, }, ), }, @@ -1085,7 +1381,7 @@ Module( 6 | with (item1, item2), item3,: ... | ^ Syntax Error: Trailing comma not allowed 7 | with (*item): ... -8 | with (item := 10 as f): ... +8 | with (*item) as f: ... | @@ -1094,130 +1390,205 @@ Module( 6 | with (item1, item2), item3,: ... 7 | with (*item): ... | ^^^^^ Syntax Error: starred expression cannot be used here -8 | with (item := 10 as f): ... -9 | with (item1, item2 := 10 as f): ... +8 | with (*item) as f: ... +9 | with (item := 10 as f): ... | | 6 | with (item1, item2), item3,: ... 7 | with (*item): ... - 8 | with (item := 10 as f): ... - | ^^^^^^^^^^ Syntax Error: unparenthesized named expression cannot be used here - 9 | with (item1, item2 := 10 as f): ... -10 | with (x for x in range(10), item): ... + 8 | with (*item) as f: ... + | ^^^^^ Syntax Error: starred expression cannot be used here + 9 | with (item := 10 as f): ... +10 | with (item1, item2 := 10 as f): ... | | 7 | with (*item): ... - 8 | with (item := 10 as f): ... - 9 | with (item1, item2 := 10 as f): ... + 8 | with (*item) as f: ... + 9 | with (item := 10 as f): ... + | ^^^^^^^^^^ Syntax Error: unparenthesized named expression cannot be used here +10 | with (item1, item2 := 10 as f): ... +11 | with (x for x in range(10), item): ... + | + + + | + 8 | with (*item) as f: ... + 9 | with (item := 10 as f): ... +10 | with (item1, item2 := 10 as f): ... | ^^^^^^^^^^^ Syntax Error: unparenthesized named expression cannot be used here -10 | with (x for x in range(10), item): ... -11 | with (item, x for x in range(10)): ... +11 | with (x for x in range(10), item): ... +12 | with (item, x for x in range(10)): ... | | - 8 | with (item := 10 as f): ... - 9 | with (item1, item2 := 10 as f): ... -10 | with (x for x in range(10), item): ... + 9 | with (item := 10 as f): ... +10 | with (item1, item2 := 10 as f): ... +11 | with (x for x in range(10), item): ... | ^^^^^^^^^^^^^^^^^^^^ Syntax Error: unparenthesized generator expression cannot be used here -11 | with (item, x for x in range(10)): ... +12 | with (item, x for x in range(10)): ... | | - 9 | with (item1, item2 := 10 as f): ... -10 | with (x for x in range(10), item): ... -11 | with (item, x for x in range(10)): ... +10 | with (item1, item2 := 10 as f): ... +11 | with (x for x in range(10), item): ... +12 | with (item, x for x in range(10)): ... | ^^^^^^^^^^^^^^^^^^^^ Syntax Error: unparenthesized generator expression cannot be used here -12 | -13 | # Make sure the parser doesn't report the same error twice +13 | +14 | # Make sure the parser doesn't report the same error twice | | -13 | # Make sure the parser doesn't report the same error twice -14 | with ((*item)): ... +14 | # Make sure the parser doesn't report the same error twice +15 | with ((*item)): ... | ^^^^^ Syntax Error: starred expression cannot be used here -15 | -16 | with (*x for x in iter, item): ... +16 | +17 | with (*x for x in iter, item): ... | | -14 | with ((*item)): ... -15 | -16 | with (*x for x in iter, item): ... +15 | with ((*item)): ... +16 | +17 | with (*x for x in iter, item): ... | ^^ Syntax Error: iterable unpacking cannot be used in a comprehension -17 | with (item1, *x for x in iter, item2): ... -18 | with (x as f, *y): ... +18 | with (item1, *x for x in iter, item2): ... +19 | with (x as f, *y): ... | | -16 | with (*x for x in iter, item): ... -17 | with (item1, *x for x in iter, item2): ... +17 | with (*x for x in iter, item): ... +18 | with (item1, *x for x in iter, item2): ... | ^^ Syntax Error: iterable unpacking cannot be used in a comprehension -18 | with (x as f, *y): ... -19 | with (x, yield y): ... +19 | with (x as f, *y): ... +20 | with (*x, y as f): ... | | -16 | with (*x for x in iter, item): ... -17 | with (item1, *x for x in iter, item2): ... -18 | with (x as f, *y): ... +17 | with (*x for x in iter, item): ... +18 | with (item1, *x for x in iter, item2): ... +19 | with (x as f, *y): ... | ^^ Syntax Error: starred expression cannot be used here -19 | with (x, yield y): ... -20 | with (x, yield y, z): ... +20 | with (*x, y as f): ... +21 | with (x, yield y): ... + | + + + | +18 | with (item1, *x for x in iter, item2): ... +19 | with (x as f, *y): ... +20 | with (*x, y as f): ... + | ^^ Syntax Error: starred expression cannot be used here +21 | with (x, yield y): ... +22 | with (x, yield y, z): ... | | -17 | with (item1, *x for x in iter, item2): ... -18 | with (x as f, *y): ... -19 | with (x, yield y): ... +19 | with (x as f, *y): ... +20 | with (*x, y as f): ... +21 | with (x, yield y): ... | ^^^^^^^ Syntax Error: yield expression cannot be used here -20 | with (x, yield y, z): ... -21 | with (x, yield from y): ... +22 | with (x, yield y, z): ... +23 | with (x, yield from y): ... | | -18 | with (x as f, *y): ... -19 | with (x, yield y): ... -20 | with (x, yield y, z): ... +20 | with (*x, y as f): ... +21 | with (x, yield y): ... +22 | with (x, yield y, z): ... | ^^^^^^^^^^ Syntax Error: yield expression cannot be used here -21 | with (x, yield from y): ... -22 | with (x as f, y) as f: ... +23 | with (x, yield from y): ... +24 | with (x as f, y) as f: ... | | -19 | with (x, yield y): ... -20 | with (x, yield y, z): ... -21 | with (x, yield from y): ... +21 | with (x, yield y): ... +22 | with (x, yield y, z): ... +23 | with (x, yield from y): ... | ^^^^^^^^^^^^ Syntax Error: yield expression cannot be used here -22 | with (x as f, y) as f: ... -23 | with (x for x in iter as y): ... +24 | with (x as f, y) as f: ... +25 | with (x for x in iter as y): ... | | -20 | with (x, yield y, z): ... -21 | with (x, yield from y): ... -22 | with (x as f, y) as f: ... +22 | with (x, yield y, z): ... +23 | with (x, yield from y): ... +24 | with (x as f, y) as f: ... | ^^ Syntax Error: expected Colon, found As -23 | with (x for x in iter as y): ... +25 | with (x for x in iter as y): ... | | -21 | with (x, yield from y): ... -22 | with (x as f, y) as f: ... -23 | with (x for x in iter as y): ... +23 | with (x, yield from y): ... +24 | with (x as f, y) as f: ... +25 | with (x for x in iter as y): ... | ^^^^^^^^^^^^^^^ Syntax Error: unparenthesized generator expression cannot be used here +26 | +27 | # The inner `(...)` is parsed as parenthesized expression + | + + + | +27 | # The inner `(...)` is parsed as parenthesized expression +28 | with ((item as f)): ... + | ^^ Syntax Error: expected Rpar, found As +29 | +30 | with (item as f), x: ... + | + + + | +27 | # The inner `(...)` is parsed as parenthesized expression +28 | with ((item as f)): ... + | ^ Syntax Error: expected Colon, found Rpar +29 | +30 | with (item as f), x: ... + | + + + | +27 | # The inner `(...)` is parsed as parenthesized expression +28 | with ((item as f)): ... + | ^ Syntax Error: Expected a statement +29 | +30 | with (item as f), x: ... + | + + + | +28 | with ((item as f)): ... +29 | +30 | with (item as f), x: ... + | ^ Syntax Error: expected Colon, found Comma +31 | with (item as f1) as f2: ... +32 | with (item1 as f, item2 := 0): ... + | + + + | +30 | with (item as f), x: ... +31 | with (item as f1) as f2: ... + | ^^ Syntax Error: expected Colon, found As +32 | with (item1 as f, item2 := 0): ... + | + + + | +30 | with (item as f), x: ... +31 | with (item as f1) as f2: ... +32 | with (item1 as f, item2 := 0): ... + | ^^^^^^^^^^ Syntax Error: unparenthesized named expression cannot be used here | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap new file mode 100644 index 0000000000000..f9ed0e97b9d2a --- /dev/null +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap @@ -0,0 +1,361 @@ +--- +source: crates/ruff_python_parser/tests/fixtures.rs +input_file: crates/ruff_python_parser/resources/invalid/statements/with/unparenthesized_with_items.py +--- +## AST + +``` +Module( + ModModule { + range: 0..249, + body: [ + With( + StmtWith { + range: 86..102, + is_async: false, + items: [ + WithItem { + range: 91..95, + context_expr: Name( + ExprName { + range: 91..95, + id: "item", + ctx: Load, + }, + ), + optional_vars: None, + }, + ], + body: [ + Pass( + StmtPass { + range: 98..102, + }, + ), + ], + }, + ), + With( + StmtWith { + range: 103..124, + is_async: false, + items: [ + WithItem { + range: 108..117, + context_expr: Name( + ExprName { + range: 108..112, + id: "item", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 116..117, + id: "x", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Pass( + StmtPass { + range: 120..124, + }, + ), + ], + }, + ), + With( + StmtWith { + range: 125..141, + is_async: false, + items: [ + WithItem { + range: 130..135, + context_expr: Starred( + ExprStarred { + range: 130..135, + value: Name( + ExprName { + range: 131..135, + id: "item", + ctx: Load, + }, + ), + ctx: Load, + }, + ), + optional_vars: None, + }, + ], + body: [ + Pass( + StmtPass { + range: 137..141, + }, + ), + ], + }, + ), + With( + StmtWith { + range: 142..163, + is_async: false, + items: [ + WithItem { + range: 147..157, + context_expr: Starred( + ExprStarred { + range: 147..152, + value: Name( + ExprName { + range: 148..152, + id: "item", + ctx: Load, + }, + ), + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 156..157, + id: "x", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Pass( + StmtPass { + range: 159..163, + }, + ), + ], + }, + ), + With( + StmtWith { + range: 164..193, + is_async: false, + items: [ + WithItem { + range: 169..175, + context_expr: Starred( + ExprStarred { + range: 169..175, + value: Name( + ExprName { + range: 170..175, + id: "item1", + ctx: Load, + }, + ), + ctx: Load, + }, + ), + optional_vars: None, + }, + WithItem { + range: 177..187, + context_expr: Name( + ExprName { + range: 177..182, + id: "item2", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 186..187, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Pass( + StmtPass { + range: 189..193, + }, + ), + ], + }, + ), + With( + StmtWith { + range: 194..223, + is_async: false, + items: [ + WithItem { + range: 199..209, + context_expr: Name( + ExprName { + range: 199..204, + id: "item1", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 208..209, + id: "f", + ctx: Store, + }, + ), + ), + }, + WithItem { + range: 211..217, + context_expr: Starred( + ExprStarred { + range: 211..217, + value: Name( + ExprName { + range: 212..217, + id: "item2", + ctx: Load, + }, + ), + ctx: Load, + }, + ), + optional_vars: None, + }, + ], + body: [ + Pass( + StmtPass { + range: 219..223, + }, + ), + ], + }, + ), + With( + StmtWith { + range: 224..249, + is_async: false, + items: [ + WithItem { + range: 229..233, + context_expr: Name( + ExprName { + range: 229..233, + id: "item", + ctx: Load, + }, + ), + optional_vars: None, + }, + WithItem { + range: 237..243, + context_expr: NumberLiteral( + ExprNumberLiteral { + range: 237..238, + value: Int( + 0, + ), + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 242..243, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Pass( + StmtPass { + range: 245..249, + }, + ), + ], + }, + ), + ], + }, +) +``` +## Errors + + | +1 | # For parenthesized with items test cases, refer to `./ambiguous_lpar_with_items.py` +2 | +3 | with item,: pass + | ^ Syntax Error: Trailing comma not allowed +4 | with item as x,: pass +5 | with *item: pass + | + + + | +3 | with item,: pass +4 | with item as x,: pass + | ^ Syntax Error: Trailing comma not allowed +5 | with *item: pass +6 | with *item as x: pass + | + + + | +3 | with item,: pass +4 | with item as x,: pass +5 | with *item: pass + | ^^^^^ Syntax Error: starred expression cannot be used here +6 | with *item as x: pass +7 | with *item1, item2 as f: pass + | + + + | +4 | with item as x,: pass +5 | with *item: pass +6 | with *item as x: pass + | ^^^^^ Syntax Error: starred expression cannot be used here +7 | with *item1, item2 as f: pass +8 | with item1 as f, *item2: pass + | + + + | +5 | with *item: pass +6 | with *item as x: pass +7 | with *item1, item2 as f: pass + | ^^^^^^ Syntax Error: starred expression cannot be used here +8 | with item1 as f, *item2: pass +9 | with item := 0 as f: pass + | + + + | +6 | with *item as x: pass +7 | with *item1, item2 as f: pass +8 | with item1 as f, *item2: pass + | ^^^^^^ Syntax Error: starred expression cannot be used here +9 | with item := 0 as f: pass + | + + + | +7 | with *item1, item2 as f: pass +8 | with item1 as f, *item2: pass +9 | with item := 0 as f: pass + | ^^ Syntax Error: expected Comma, found ColonEqual + | diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap index 4bd374d40f5f5..b17e20da0f7ab 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap @@ -7,18 +7,18 @@ input_file: crates/ruff_python_parser/resources/valid/statement/ambiguous_lpar_w ``` Module( ModModule { - range: 0..3387, + range: 0..3620, body: [ With( StmtWith { - range: 326..340, + range: 588..604, is_async: false, items: [ WithItem { - range: 331..335, + range: 594..598, context_expr: Name( ExprName { - range: 331..335, + range: 594..598, id: "item", ctx: Load, }, @@ -29,10 +29,10 @@ Module( body: [ Expr( StmtExpr { - range: 337..340, + range: 601..604, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 337..340, + range: 601..604, }, ), }, @@ -42,36 +42,28 @@ Module( ), With( StmtWith { - range: 341..360, + range: 605..622, is_async: false, items: [ WithItem { - range: 346..355, + range: 611..615, context_expr: Name( ExprName { - range: 346..350, + range: 611..615, id: "item", ctx: Load, }, ), - optional_vars: Some( - Name( - ExprName { - range: 354..355, - id: "f", - ctx: Store, - }, - ), - ), + optional_vars: None, }, ], body: [ Expr( StmtExpr { - range: 357..360, + range: 619..622, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 357..360, + range: 619..622, }, ), }, @@ -81,14 +73,14 @@ Module( ), With( StmtWith { - range: 655..671, + range: 648..668, is_async: false, items: [ WithItem { - range: 661..665, + range: 654..662, context_expr: Name( ExprName { - range: 661..665, + range: 656..660, id: "item", ctx: Load, }, @@ -99,10 +91,10 @@ Module( body: [ Expr( StmtExpr { - range: 668..671, + range: 665..668, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 668..671, + range: 665..668, }, ), }, @@ -112,15 +104,26 @@ Module( ), With( StmtWith { - range: 672..689, + range: 669..693, is_async: false, items: [ WithItem { - range: 678..682, + range: 675..680, context_expr: Name( ExprName { - range: 678..682, - id: "item", + range: 675..680, + id: "item1", + ctx: Load, + }, + ), + optional_vars: None, + }, + WithItem { + range: 682..687, + context_expr: Name( + ExprName { + range: 682..687, + id: "item2", ctx: Load, }, ), @@ -130,10 +133,10 @@ Module( body: [ Expr( StmtExpr { - range: 686..689, + range: 690..693, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 686..689, + range: 690..693, }, ), }, @@ -143,14 +146,14 @@ Module( ), With( StmtWith { - range: 715..739, + range: 694..719, is_async: false, items: [ WithItem { - range: 721..726, + range: 700..705, context_expr: Name( ExprName { - range: 721..726, + range: 700..705, id: "item1", ctx: Load, }, @@ -158,10 +161,10 @@ Module( optional_vars: None, }, WithItem { - range: 728..733, + range: 707..712, context_expr: Name( ExprName { - range: 728..733, + range: 707..712, id: "item2", ctx: Load, }, @@ -172,10 +175,10 @@ Module( body: [ Expr( StmtExpr { - range: 736..739, + range: 716..719, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 736..739, + range: 716..719, }, ), }, @@ -185,14 +188,14 @@ Module( ), With( StmtWith { - range: 740..765, + range: 745..794, is_async: false, items: [ WithItem { - range: 746..751, + range: 751..758, context_expr: Name( ExprName { - range: 746..751, + range: 752..757, id: "item1", ctx: Load, }, @@ -200,24 +203,54 @@ Module( optional_vars: None, }, WithItem { - range: 753..758, + range: 760..767, context_expr: Name( ExprName { - range: 753..758, + range: 761..766, id: "item2", ctx: Load, }, ), optional_vars: None, }, + WithItem { + range: 769..779, + context_expr: Name( + ExprName { + range: 769..774, + id: "item3", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 778..779, + id: "f", + ctx: Store, + }, + ), + ), + }, + WithItem { + range: 781..788, + context_expr: Name( + ExprName { + range: 782..787, + id: "item4", + ctx: Load, + }, + ), + optional_vars: None, + }, ], body: [ Expr( StmtExpr { - range: 762..765, + range: 791..794, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 762..765, + range: 791..794, }, ), }, @@ -227,25 +260,25 @@ Module( ), With( StmtWith { - range: 791..824, + range: 795..828, is_async: false, items: [ WithItem { - range: 797..811, + range: 801..815, context_expr: Tuple( ExprTuple { - range: 797..811, + range: 801..815, elts: [ Name( ExprName { - range: 798..803, + range: 802..807, id: "item1", ctx: Load, }, ), Name( ExprName { - range: 805..810, + range: 809..814, id: "item2", ctx: Load, }, @@ -258,10 +291,10 @@ Module( optional_vars: None, }, WithItem { - range: 813..818, + range: 817..822, context_expr: Name( ExprName { - range: 813..818, + range: 817..822, id: "item3", ctx: Load, }, @@ -272,10 +305,10 @@ Module( body: [ Expr( StmtExpr { - range: 821..824, + range: 825..828, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 821..824, + range: 825..828, }, ), }, @@ -285,14 +318,69 @@ Module( ), With( StmtWith { - range: 825..861, + range: 829..852, is_async: false, items: [ WithItem { - range: 831..842, + range: 835..846, + context_expr: Tuple( + ExprTuple { + range: 835..841, + elts: [ + Name( + ExprName { + range: 836..837, + id: "x", + ctx: Load, + }, + ), + Name( + ExprName { + range: 839..840, + id: "y", + ctx: Load, + }, + ), + ], + ctx: Load, + parenthesized: true, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 845..846, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Expr( + StmtExpr { + range: 849..852, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 849..852, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 853..889, + is_async: false, + items: [ + WithItem { + range: 859..870, context_expr: Name( ExprName { - range: 831..836, + range: 859..864, id: "item1", ctx: Load, }, @@ -300,7 +388,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 840..842, + range: 868..870, id: "f1", ctx: Store, }, @@ -308,10 +396,10 @@ Module( ), }, WithItem { - range: 844..855, + range: 872..883, context_expr: Name( ExprName { - range: 844..849, + range: 872..877, id: "item2", ctx: Load, }, @@ -319,7 +407,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 853..855, + range: 881..883, id: "f2", ctx: Store, }, @@ -330,10 +418,10 @@ Module( body: [ Expr( StmtExpr { - range: 858..861, + range: 886..889, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 858..861, + range: 886..889, }, ), }, @@ -343,14 +431,14 @@ Module( ), With( StmtWith { - range: 862..899, + range: 890..927, is_async: false, items: [ WithItem { - range: 868..879, + range: 896..907, context_expr: Name( ExprName { - range: 868..873, + range: 896..901, id: "item1", ctx: Load, }, @@ -358,7 +446,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 877..879, + range: 905..907, id: "f1", ctx: Store, }, @@ -366,10 +454,10 @@ Module( ), }, WithItem { - range: 881..892, + range: 909..920, context_expr: Name( ExprName { - range: 881..886, + range: 909..914, id: "item2", ctx: Load, }, @@ -377,7 +465,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 890..892, + range: 918..920, id: "f2", ctx: Store, }, @@ -388,10 +476,10 @@ Module( body: [ Expr( StmtExpr { - range: 896..899, + range: 924..927, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 896..899, + range: 924..927, }, ), }, @@ -401,17 +489,17 @@ Module( ), With( StmtWith { - range: 925..948, + range: 953..976, is_async: false, items: [ WithItem { - range: 931..941, + range: 959..969, context_expr: Compare( ExprCompare { - range: 931..941, + range: 959..969, left: Name( ExprName { - range: 931..935, + range: 959..963, id: "item", ctx: Load, }, @@ -422,7 +510,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - range: 939..941, + range: 967..969, value: Int( 10, ), @@ -437,10 +525,10 @@ Module( body: [ Expr( StmtExpr { - range: 945..948, + range: 973..976, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 945..948, + range: 973..976, }, ), }, @@ -450,24 +538,24 @@ Module( ), With( StmtWith { - range: 949..973, + range: 977..1001, is_async: false, items: [ WithItem { - range: 955..967, + range: 983..995, context_expr: Named( ExprNamed { - range: 956..966, + range: 984..994, target: Name( ExprName { - range: 956..960, + range: 984..988, id: "item", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 964..966, + range: 992..994, value: Int( 10, ), @@ -481,10 +569,10 @@ Module( body: [ Expr( StmtExpr { - range: 970..973, + range: 998..1001, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 970..973, + range: 998..1001, }, ), }, @@ -494,28 +582,28 @@ Module( ), With( StmtWith { - range: 974..999, + range: 1002..1027, is_async: false, items: [ WithItem { - range: 980..993, + range: 1008..1021, context_expr: Tuple( ExprTuple { - range: 980..993, + range: 1008..1021, elts: [ Named( ExprNamed { - range: 981..991, + range: 1009..1019, target: Name( ExprName { - range: 981..985, + range: 1009..1013, id: "item", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 989..991, + range: 1017..1019, value: Int( 10, ), @@ -534,10 +622,10 @@ Module( body: [ Expr( StmtExpr { - range: 996..999, + range: 1024..1027, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 996..999, + range: 1024..1027, }, ), }, @@ -547,21 +635,21 @@ Module( ), With( StmtWith { - range: 1000..1020, + range: 1028..1048, is_async: false, items: [ WithItem { - range: 1006..1014, + range: 1034..1042, context_expr: Tuple( ExprTuple { - range: 1006..1014, + range: 1034..1042, elts: [ Starred( ExprStarred { - range: 1007..1012, + range: 1035..1040, value: Name( ExprName { - range: 1008..1012, + range: 1036..1040, id: "item", ctx: Load, }, @@ -580,10 +668,10 @@ Module( body: [ Expr( StmtExpr { - range: 1017..1020, + range: 1045..1048, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1017..1020, + range: 1045..1048, }, ), }, @@ -593,24 +681,24 @@ Module( ), With( StmtWith { - range: 1021..1053, + range: 1049..1081, is_async: false, items: [ WithItem { - range: 1027..1040, + range: 1055..1068, context_expr: Named( ExprNamed { - range: 1028..1039, + range: 1056..1067, target: Name( ExprName { - range: 1028..1033, + range: 1056..1061, id: "item1", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 1037..1039, + range: 1065..1067, value: Int( 10, ), @@ -621,10 +709,10 @@ Module( optional_vars: None, }, WithItem { - range: 1042..1047, + range: 1070..1075, context_expr: Name( ExprName { - range: 1042..1047, + range: 1070..1075, id: "item2", ctx: Load, }, @@ -635,10 +723,10 @@ Module( body: [ Expr( StmtExpr { - range: 1050..1053, + range: 1078..1081, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1050..1053, + range: 1078..1081, }, ), }, @@ -648,23 +736,86 @@ Module( ), With( StmtWith { - range: 1054..1071, + range: 1082..1119, is_async: false, items: [ WithItem { - range: 1060..1065, + range: 1088..1098, + context_expr: Name( + ExprName { + range: 1088..1093, + id: "item1", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 1097..1098, + id: "f", + ctx: Store, + }, + ), + ), + }, + WithItem { + range: 1100..1113, + context_expr: Named( + ExprNamed { + range: 1101..1112, + target: Name( + ExprName { + range: 1101..1106, + id: "item2", + ctx: Store, + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 1110..1112, + value: Int( + 10, + ), + }, + ), + }, + ), + optional_vars: None, + }, + ], + body: [ + Expr( + StmtExpr { + range: 1116..1119, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 1116..1119, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 1120..1137, + is_async: false, + items: [ + WithItem { + range: 1126..1131, context_expr: Call( ExprCall { - range: 1060..1065, + range: 1126..1131, func: Name( ExprName { - range: 1060..1063, + range: 1126..1129, id: "foo", ctx: Load, }, ), arguments: Arguments { - range: 1063..1065, + range: 1129..1131, args: [], keywords: [], }, @@ -676,10 +827,10 @@ Module( body: [ Expr( StmtExpr { - range: 1068..1071, + range: 1134..1137, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1068..1071, + range: 1134..1137, }, ), }, @@ -689,23 +840,23 @@ Module( ), With( StmtWith { - range: 1072..1090, + range: 1138..1156, is_async: false, items: [ WithItem { - range: 1078..1083, + range: 1144..1149, context_expr: Call( ExprCall { - range: 1078..1083, + range: 1144..1149, func: Name( ExprName { - range: 1078..1081, + range: 1144..1147, id: "foo", ctx: Load, }, ), arguments: Arguments { - range: 1081..1083, + range: 1147..1149, args: [], keywords: [], }, @@ -717,10 +868,10 @@ Module( body: [ Expr( StmtExpr { - range: 1087..1090, + range: 1153..1156, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1087..1090, + range: 1153..1156, }, ), }, @@ -730,23 +881,23 @@ Module( ), With( StmtWith { - range: 1091..1113, + range: 1157..1179, is_async: false, items: [ WithItem { - range: 1097..1107, + range: 1163..1173, context_expr: Call( ExprCall { - range: 1097..1102, + range: 1163..1168, func: Name( ExprName { - range: 1097..1100, + range: 1163..1166, id: "foo", ctx: Load, }, ), arguments: Arguments { - range: 1100..1102, + range: 1166..1168, args: [], keywords: [], }, @@ -755,7 +906,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 1106..1107, + range: 1172..1173, id: "f", ctx: Store, }, @@ -766,10 +917,10 @@ Module( body: [ Expr( StmtExpr { - range: 1110..1113, + range: 1176..1179, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1110..1113, + range: 1176..1179, }, ), }, @@ -779,26 +930,26 @@ Module( ), With( StmtWith { - range: 1114..1141, + range: 1180..1207, is_async: false, items: [ WithItem { - range: 1120..1135, + range: 1186..1201, context_expr: FString( ExprFString { - range: 1120..1135, + range: 1186..1201, value: FStringValue { inner: Single( FString( FString { - range: 1120..1135, + range: 1186..1201, elements: [ Expression( FStringExpressionElement { - range: 1122..1134, + range: 1188..1200, expression: Name( ExprName { - range: 1123..1127, + range: 1189..1193, id: "item", ctx: Load, }, @@ -807,11 +958,11 @@ Module( conversion: None, format_spec: Some( FStringFormatSpec { - range: 1129..1133, + range: 1195..1199, elements: [ Literal( FStringLiteralElement { - range: 1129..1133, + range: 1195..1199, value: "= 42", }, ), @@ -838,10 +989,10 @@ Module( body: [ Expr( StmtExpr { - range: 1138..1141, + range: 1204..1207, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1138..1141, + range: 1204..1207, }, ), }, @@ -851,36 +1002,36 @@ Module( ), With( StmtWith { - range: 1142..1171, + range: 1208..1237, is_async: false, items: [ WithItem { - range: 1148..1165, + range: 1214..1231, context_expr: FString( ExprFString { - range: 1148..1165, + range: 1214..1231, value: FStringValue { inner: Single( FString( FString { - range: 1148..1165, + range: 1214..1231, elements: [ Expression( FStringExpressionElement { - range: 1150..1164, + range: 1216..1230, expression: Named( ExprNamed { - range: 1152..1162, + range: 1218..1228, target: Name( ExprName { - range: 1152..1156, + range: 1218..1222, id: "item", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 1160..1162, + range: 1226..1228, value: Int( 42, ), @@ -911,10 +1062,10 @@ Module( body: [ Expr( StmtExpr { - range: 1168..1171, + range: 1234..1237, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1168..1171, + range: 1234..1237, }, ), }, @@ -924,47 +1075,47 @@ Module( ), With( StmtWith { - range: 1172..1212, + range: 1238..1278, is_async: false, items: [ WithItem { - range: 1178..1200, + range: 1244..1266, context_expr: Generator( ExprGenerator { - range: 1178..1200, + range: 1244..1266, elt: Name( ExprName { - range: 1179..1180, + range: 1245..1246, id: "x", ctx: Load, }, ), generators: [ Comprehension { - range: 1181..1199, + range: 1247..1265, target: Name( ExprName { - range: 1185..1186, + range: 1251..1252, id: "x", ctx: Store, }, ), iter: Call( ExprCall { - range: 1190..1199, + range: 1256..1265, func: Name( ExprName { - range: 1190..1195, + range: 1256..1261, id: "range", ctx: Load, }, ), arguments: Arguments { - range: 1195..1199, + range: 1261..1265, args: [ NumberLiteral( ExprNumberLiteral { - range: 1196..1198, + range: 1262..1264, value: Int( 10, ), @@ -985,10 +1136,10 @@ Module( optional_vars: None, }, WithItem { - range: 1202..1206, + range: 1268..1272, context_expr: Name( ExprName { - range: 1202..1206, + range: 1268..1272, id: "item", ctx: Load, }, @@ -999,10 +1150,10 @@ Module( body: [ Expr( StmtExpr { - range: 1209..1212, + range: 1275..1278, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1209..1212, + range: 1275..1278, }, ), }, @@ -1012,14 +1163,14 @@ Module( ), With( StmtWith { - range: 1213..1253, + range: 1279..1319, is_async: false, items: [ WithItem { - range: 1219..1223, + range: 1285..1289, context_expr: Name( ExprName { - range: 1219..1223, + range: 1285..1289, id: "item", ctx: Load, }, @@ -1027,43 +1178,43 @@ Module( optional_vars: None, }, WithItem { - range: 1225..1247, + range: 1291..1313, context_expr: Generator( ExprGenerator { - range: 1225..1247, + range: 1291..1313, elt: Name( ExprName { - range: 1226..1227, + range: 1292..1293, id: "x", ctx: Load, }, ), generators: [ Comprehension { - range: 1228..1246, + range: 1294..1312, target: Name( ExprName { - range: 1232..1233, + range: 1298..1299, id: "x", ctx: Store, }, ), iter: Call( ExprCall { - range: 1237..1246, + range: 1303..1312, func: Name( ExprName { - range: 1237..1242, + range: 1303..1308, id: "range", ctx: Load, }, ), arguments: Arguments { - range: 1242..1246, + range: 1308..1312, args: [ NumberLiteral( ExprNumberLiteral { - range: 1243..1245, + range: 1309..1311, value: Int( 10, ), @@ -1087,10 +1238,10 @@ Module( body: [ Expr( StmtExpr { - range: 1250..1253, + range: 1316..1319, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1250..1253, + range: 1316..1319, }, ), }, @@ -1100,14 +1251,14 @@ Module( ), With( StmtWith { - range: 1254..1300, + range: 1320..1366, is_async: false, items: [ WithItem { - range: 1260..1264, + range: 1326..1330, context_expr: Name( ExprName { - range: 1260..1264, + range: 1326..1330, id: "item", ctx: Load, }, @@ -1115,43 +1266,43 @@ Module( optional_vars: None, }, WithItem { - range: 1266..1288, + range: 1332..1354, context_expr: Generator( ExprGenerator { - range: 1266..1288, + range: 1332..1354, elt: Name( ExprName { - range: 1267..1268, + range: 1333..1334, id: "x", ctx: Load, }, ), generators: [ Comprehension { - range: 1269..1287, + range: 1335..1353, target: Name( ExprName { - range: 1273..1274, + range: 1339..1340, id: "x", ctx: Store, }, ), iter: Call( ExprCall { - range: 1278..1287, + range: 1344..1353, func: Name( ExprName { - range: 1278..1283, + range: 1344..1349, id: "range", ctx: Load, }, ), arguments: Arguments { - range: 1283..1287, + range: 1349..1353, args: [ NumberLiteral( ExprNumberLiteral { - range: 1284..1286, + range: 1350..1352, value: Int( 10, ), @@ -1172,10 +1323,10 @@ Module( optional_vars: None, }, WithItem { - range: 1290..1294, + range: 1356..1360, context_expr: Name( ExprName { - range: 1290..1294, + range: 1356..1360, id: "item", ctx: Load, }, @@ -1186,10 +1337,10 @@ Module( body: [ Expr( StmtExpr { - range: 1297..1300, + range: 1363..1366, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1297..1300, + range: 1363..1366, }, ), }, @@ -1199,28 +1350,28 @@ Module( ), With( StmtWith { - range: 1301..1322, + range: 1367..1388, is_async: false, items: [ WithItem { - range: 1307..1316, + range: 1373..1382, context_expr: Subscript( ExprSubscript { - range: 1307..1316, + range: 1373..1382, value: Name( ExprName { - range: 1307..1311, + range: 1373..1377, id: "data", ctx: Load, }, ), slice: Slice( ExprSlice { - range: 1312..1315, + range: 1378..1381, lower: Some( NumberLiteral( ExprNumberLiteral { - range: 1312..1313, + range: 1378..1379, value: Int( 1, ), @@ -1230,7 +1381,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - range: 1314..1315, + range: 1380..1381, value: Int( 2, ), @@ -1249,10 +1400,10 @@ Module( body: [ Expr( StmtExpr { - range: 1319..1322, + range: 1385..1388, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1319..1322, + range: 1385..1388, }, ), }, @@ -1262,28 +1413,28 @@ Module( ), With( StmtWith { - range: 1323..1349, + range: 1389..1415, is_async: false, items: [ WithItem { - range: 1329..1343, + range: 1395..1409, context_expr: Subscript( ExprSubscript { - range: 1329..1338, + range: 1395..1404, value: Name( ExprName { - range: 1329..1333, + range: 1395..1399, id: "data", ctx: Load, }, ), slice: Slice( ExprSlice { - range: 1334..1337, + range: 1400..1403, lower: Some( NumberLiteral( ExprNumberLiteral { - range: 1334..1335, + range: 1400..1401, value: Int( 1, ), @@ -1293,7 +1444,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - range: 1336..1337, + range: 1402..1403, value: Int( 2, ), @@ -1309,7 +1460,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 1342..1343, + range: 1408..1409, id: "f", ctx: Store, }, @@ -1320,10 +1471,10 @@ Module( body: [ Expr( StmtExpr { - range: 1346..1349, + range: 1412..1415, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1346..1349, + range: 1412..1415, }, ), }, @@ -1333,34 +1484,34 @@ Module( ), With( StmtWith { - range: 1350..1384, + range: 1416..1450, is_async: false, items: [ WithItem { - range: 1356..1378, + range: 1422..1444, context_expr: Generator( ExprGenerator { - range: 1356..1373, + range: 1422..1439, elt: Name( ExprName { - range: 1357..1358, + range: 1423..1424, id: "x", ctx: Load, }, ), generators: [ Comprehension { - range: 1359..1372, + range: 1425..1438, target: Name( ExprName { - range: 1363..1364, + range: 1429..1430, id: "x", ctx: Store, }, ), iter: Name( ExprName { - range: 1368..1372, + range: 1434..1438, id: "iter", ctx: Load, }, @@ -1375,7 +1526,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 1377..1378, + range: 1443..1444, id: "y", ctx: Store, }, @@ -1386,10 +1537,10 @@ Module( body: [ Expr( StmtExpr { - range: 1381..1384, + range: 1447..1450, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1381..1384, + range: 1447..1450, }, ), }, @@ -1399,14 +1550,14 @@ Module( ), With( StmtWith { - range: 1597..1618, + range: 1663..1684, is_async: false, items: [ WithItem { - range: 1602..1613, + range: 1668..1679, context_expr: Name( ExprName { - range: 1603..1607, + range: 1669..1673, id: "item", ctx: Load, }, @@ -1414,7 +1565,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 1612..1613, + range: 1678..1679, id: "f", ctx: Store, }, @@ -1425,10 +1576,10 @@ Module( body: [ Expr( StmtExpr { - range: 1615..1618, + range: 1681..1684, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1615..1618, + range: 1681..1684, }, ), }, @@ -1438,24 +1589,24 @@ Module( ), With( StmtWith { - range: 1619..1641, + range: 1685..1707, is_async: false, items: [ WithItem { - range: 1624..1636, + range: 1690..1702, context_expr: Named( ExprNamed { - range: 1625..1635, + range: 1691..1701, target: Name( ExprName { - range: 1625..1629, + range: 1691..1695, id: "item", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 1633..1635, + range: 1699..1701, value: Int( 10, ), @@ -1469,10 +1620,62 @@ Module( body: [ Expr( StmtExpr { - range: 1638..1641, + range: 1704..1707, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 1704..1707, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 1708..1735, + is_async: false, + items: [ + WithItem { + range: 1713..1730, + context_expr: Named( + ExprNamed { + range: 1714..1724, + target: Name( + ExprName { + range: 1714..1718, + id: "item", + ctx: Store, + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 1722..1724, + value: Int( + 10, + ), + }, + ), + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 1729..1730, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Expr( + StmtExpr { + range: 1732..1735, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1638..1641, + range: 1732..1735, }, ), }, @@ -1482,24 +1685,24 @@ Module( ), With( StmtWith { - range: 1642..1668, + range: 1736..1762, is_async: false, items: [ WithItem { - range: 1647..1663, + range: 1741..1757, context_expr: Named( ExprNamed { - range: 1650..1659, + range: 1744..1753, target: Name( ExprName { - range: 1650..1654, + range: 1744..1748, id: "item", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 1658..1659, + range: 1752..1753, value: Int( 1, ), @@ -1513,10 +1716,10 @@ Module( body: [ Expr( StmtExpr { - range: 1665..1668, + range: 1759..1762, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1665..1668, + range: 1759..1762, }, ), }, @@ -1526,24 +1729,24 @@ Module( ), With( StmtWith { - range: 1669..1699, + range: 1763..1793, is_async: false, items: [ WithItem { - range: 1674..1687, + range: 1768..1781, context_expr: Named( ExprNamed { - range: 1675..1686, + range: 1769..1780, target: Name( ExprName { - range: 1675..1680, + range: 1769..1774, id: "item1", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 1684..1686, + range: 1778..1780, value: Int( 42, ), @@ -1554,10 +1757,10 @@ Module( optional_vars: None, }, WithItem { - range: 1689..1694, + range: 1783..1788, context_expr: Name( ExprName { - range: 1689..1694, + range: 1783..1788, id: "item2", ctx: Load, }, @@ -1568,10 +1771,10 @@ Module( body: [ Expr( StmtExpr { - range: 1696..1699, + range: 1790..1793, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1696..1699, + range: 1790..1793, }, ), }, @@ -1581,23 +1784,23 @@ Module( ), With( StmtWith { - range: 1700..1734, + range: 1794..1828, is_async: false, items: [ WithItem { - range: 1705..1729, + range: 1799..1823, context_expr: Call( ExprCall { - range: 1705..1729, + range: 1799..1823, func: Attribute( ExprAttribute { - range: 1705..1727, + range: 1799..1821, value: BinOp( ExprBinOp { - range: 1706..1721, + range: 1800..1815, left: Name( ExprName { - range: 1706..1710, + range: 1800..1804, id: "root", ctx: Load, }, @@ -1605,7 +1808,7 @@ Module( op: Add, right: Name( ExprName { - range: 1713..1721, + range: 1807..1815, id: "filename", ctx: Load, }, @@ -1614,13 +1817,13 @@ Module( ), attr: Identifier { id: "read", - range: 1723..1727, + range: 1817..1821, }, ctx: Load, }, ), arguments: Arguments { - range: 1727..1729, + range: 1821..1823, args: [], keywords: [], }, @@ -1632,10 +1835,10 @@ Module( body: [ Expr( StmtExpr { - range: 1731..1734, + range: 1825..1828, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1731..1734, + range: 1825..1828, }, ), }, @@ -1645,23 +1848,23 @@ Module( ), With( StmtWith { - range: 1757..1796, + range: 1851..1890, is_async: false, items: [ WithItem { - range: 1762..1791, + range: 1856..1885, context_expr: Call( ExprCall { - range: 1762..1786, + range: 1856..1880, func: Attribute( ExprAttribute { - range: 1762..1784, + range: 1856..1878, value: BinOp( ExprBinOp { - range: 1763..1778, + range: 1857..1872, left: Name( ExprName { - range: 1763..1767, + range: 1857..1861, id: "root", ctx: Load, }, @@ -1669,7 +1872,7 @@ Module( op: Add, right: Name( ExprName { - range: 1770..1778, + range: 1864..1872, id: "filename", ctx: Load, }, @@ -1678,13 +1881,13 @@ Module( ), attr: Identifier { id: "read", - range: 1780..1784, + range: 1874..1878, }, ctx: Load, }, ), arguments: Arguments { - range: 1784..1786, + range: 1878..1880, args: [], keywords: [], }, @@ -1693,7 +1896,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 1790..1791, + range: 1884..1885, id: "f", ctx: Store, }, @@ -1704,10 +1907,10 @@ Module( body: [ Expr( StmtExpr { - range: 1793..1796, + range: 1887..1890, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1793..1796, + range: 1887..1890, }, ), }, @@ -1717,23 +1920,23 @@ Module( ), With( StmtWith { - range: 1819..1836, + range: 1913..1930, is_async: false, items: [ WithItem { - range: 1824..1831, + range: 1918..1925, context_expr: Call( ExprCall { - range: 1824..1831, + range: 1918..1925, func: Name( ExprName { - range: 1825..1828, + range: 1919..1922, id: "foo", ctx: Load, }, ), arguments: Arguments { - range: 1829..1831, + range: 1923..1925, args: [], keywords: [], }, @@ -1745,10 +1948,10 @@ Module( body: [ Expr( StmtExpr { - range: 1833..1836, + range: 1927..1930, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1833..1836, + range: 1927..1930, }, ), }, @@ -1758,23 +1961,23 @@ Module( ), With( StmtWith { - range: 1859..1881, + range: 1953..1975, is_async: false, items: [ WithItem { - range: 1864..1876, + range: 1958..1970, context_expr: Call( ExprCall { - range: 1864..1871, + range: 1958..1965, func: Name( ExprName { - range: 1865..1868, + range: 1959..1962, id: "foo", ctx: Load, }, ), arguments: Arguments { - range: 1869..1871, + range: 1963..1965, args: [], keywords: [], }, @@ -1783,7 +1986,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 1875..1876, + range: 1969..1970, id: "f", ctx: Store, }, @@ -1794,10 +1997,10 @@ Module( body: [ Expr( StmtExpr { - range: 1878..1881, + range: 1972..1975, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1878..1881, + range: 1972..1975, }, ), }, @@ -1807,23 +2010,23 @@ Module( ), With( StmtWith { - range: 1904..1926, + range: 1998..2020, is_async: false, items: [ WithItem { - range: 1909..1921, + range: 2003..2015, context_expr: Call( ExprCall { - range: 1910..1915, + range: 2004..2009, func: Name( ExprName { - range: 1910..1913, + range: 2004..2007, id: "foo", ctx: Load, }, ), arguments: Arguments { - range: 1913..1915, + range: 2007..2009, args: [], keywords: [], }, @@ -1832,7 +2035,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 1920..1921, + range: 2014..2015, id: "f", ctx: Store, }, @@ -1843,10 +2046,10 @@ Module( body: [ Expr( StmtExpr { - range: 1923..1926, + range: 2017..2020, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1923..1926, + range: 2017..2020, }, ), }, @@ -1856,28 +2059,28 @@ Module( ), With( StmtWith { - range: 1927..1953, + range: 2021..2047, is_async: false, items: [ WithItem { - range: 1932..1948, + range: 2026..2042, context_expr: Subscript( ExprSubscript { - range: 1933..1942, + range: 2027..2036, value: Name( ExprName { - range: 1933..1937, + range: 2027..2031, id: "data", ctx: Load, }, ), slice: Slice( ExprSlice { - range: 1938..1941, + range: 2032..2035, lower: Some( NumberLiteral( ExprNumberLiteral { - range: 1938..1939, + range: 2032..2033, value: Int( 1, ), @@ -1887,7 +2090,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - range: 1940..1941, + range: 2034..2035, value: Int( 2, ), @@ -1903,7 +2106,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 1947..1948, + range: 2041..2042, id: "f", ctx: Store, }, @@ -1914,10 +2117,10 @@ Module( body: [ Expr( StmtExpr { - range: 1950..1953, + range: 2044..2047, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1950..1953, + range: 2044..2047, }, ), }, @@ -1927,21 +2130,21 @@ Module( ), With( StmtWith { - range: 1954..1976, + range: 2048..2070, is_async: false, items: [ WithItem { - range: 1959..1971, + range: 2053..2065, context_expr: Subscript( ExprSubscript { - range: 1959..1971, + range: 2053..2065, value: Tuple( ExprTuple { - range: 1959..1968, + range: 2053..2062, elts: [ NumberLiteral( ExprNumberLiteral { - range: 1960..1961, + range: 2054..2055, value: Int( 1, ), @@ -1949,7 +2152,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - range: 1963..1964, + range: 2057..2058, value: Int( 2, ), @@ -1957,7 +2160,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - range: 1966..1967, + range: 2060..2061, value: Int( 3, ), @@ -1970,7 +2173,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - range: 1969..1970, + range: 2063..2064, value: Int( 0, ), @@ -1985,10 +2188,10 @@ Module( body: [ Expr( StmtExpr { - range: 1973..1976, + range: 2067..2070, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 1973..1976, + range: 2067..2070, }, ), }, @@ -1998,21 +2201,21 @@ Module( ), With( StmtWith { - range: 1999..2026, + range: 2093..2120, is_async: false, items: [ WithItem { - range: 2004..2021, + range: 2098..2115, context_expr: Subscript( ExprSubscript { - range: 2004..2016, + range: 2098..2110, value: Tuple( ExprTuple { - range: 2004..2013, + range: 2098..2107, elts: [ NumberLiteral( ExprNumberLiteral { - range: 2005..2006, + range: 2099..2100, value: Int( 1, ), @@ -2020,7 +2223,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - range: 2008..2009, + range: 2102..2103, value: Int( 2, ), @@ -2028,7 +2231,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - range: 2011..2012, + range: 2105..2106, value: Int( 3, ), @@ -2041,7 +2244,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - range: 2014..2015, + range: 2108..2109, value: Int( 0, ), @@ -2053,7 +2256,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2020..2021, + range: 2114..2115, id: "f", ctx: Store, }, @@ -2064,10 +2267,10 @@ Module( body: [ Expr( StmtExpr { - range: 2023..2026, + range: 2117..2120, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2023..2026, + range: 2117..2120, }, ), }, @@ -2077,14 +2280,14 @@ Module( ), With( StmtWith { - range: 2049..2075, + range: 2143..2169, is_async: false, items: [ WithItem { - range: 2054..2061, + range: 2148..2155, context_expr: Name( ExprName { - range: 2055..2060, + range: 2149..2154, id: "item1", ctx: Load, }, @@ -2092,10 +2295,10 @@ Module( optional_vars: None, }, WithItem { - range: 2063..2070, + range: 2157..2164, context_expr: Name( ExprName { - range: 2064..2069, + range: 2158..2163, id: "item2", ctx: Load, }, @@ -2106,10 +2309,10 @@ Module( body: [ Expr( StmtExpr { - range: 2072..2075, + range: 2166..2169, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2072..2075, + range: 2166..2169, }, ), }, @@ -2119,18 +2322,156 @@ Module( ), With( StmtWith { - range: 2076..2095, + range: 2170..2210, is_async: false, items: [ WithItem { - range: 2081..2090, + range: 2175..2189, + context_expr: Call( + ExprCall { + range: 2176..2188, + func: Name( + ExprName { + range: 2176..2180, + id: "open", + ctx: Load, + }, + ), + arguments: Arguments { + range: 2180..2188, + args: [ + StringLiteral( + ExprStringLiteral { + range: 2181..2187, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 2181..2187, + value: "a.py", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + }, + }, + ), + }, + }, + ), + ], + keywords: [], + }, + }, + ), + optional_vars: None, + }, + WithItem { + range: 2191..2205, + context_expr: Call( + ExprCall { + range: 2192..2204, + func: Name( + ExprName { + range: 2192..2196, + id: "open", + ctx: Load, + }, + ), + arguments: Arguments { + range: 2196..2204, + args: [ + StringLiteral( + ExprStringLiteral { + range: 2197..2203, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 2197..2203, + value: "b.py", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + }, + }, + ), + }, + }, + ), + ], + keywords: [], + }, + }, + ), + optional_vars: None, + }, + ], + body: [ + Expr( + StmtExpr { + range: 2207..2210, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 2207..2210, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 2211..2230, + is_async: false, + items: [ + WithItem { + range: 2216..2225, + context_expr: Yield( + ExprYield { + range: 2217..2224, + value: Some( + Name( + ExprName { + range: 2223..2224, + id: "x", + ctx: Load, + }, + ), + ), + }, + ), + optional_vars: None, + }, + ], + body: [ + Expr( + StmtExpr { + range: 2227..2230, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 2227..2230, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 2231..2252, + is_async: false, + items: [ + WithItem { + range: 2237..2246, context_expr: Yield( ExprYield { - range: 2082..2089, + range: 2238..2245, value: Some( Name( ExprName { - range: 2088..2089, + range: 2244..2245, id: "x", ctx: Load, }, @@ -2144,10 +2485,82 @@ Module( body: [ Expr( StmtExpr { - range: 2092..2095, + range: 2249..2252, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 2249..2252, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 2253..2277, + is_async: false, + items: [ + WithItem { + range: 2258..2272, + context_expr: YieldFrom( + ExprYieldFrom { + range: 2259..2271, + value: Name( + ExprName { + range: 2270..2271, + id: "x", + ctx: Load, + }, + ), + }, + ), + optional_vars: None, + }, + ], + body: [ + Expr( + StmtExpr { + range: 2274..2277, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 2274..2277, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 2278..2304, + is_async: false, + items: [ + WithItem { + range: 2284..2298, + context_expr: YieldFrom( + ExprYieldFrom { + range: 2285..2297, + value: Name( + ExprName { + range: 2296..2297, + id: "x", + ctx: Load, + }, + ), + }, + ), + optional_vars: None, + }, + ], + body: [ + Expr( + StmtExpr { + range: 2301..2304, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2092..2095, + range: 2301..2304, }, ), }, @@ -2157,18 +2570,18 @@ Module( ), With( StmtWith { - range: 2096..2120, + range: 2305..2329, is_async: false, items: [ WithItem { - range: 2101..2115, + range: 2310..2324, context_expr: Yield( ExprYield { - range: 2102..2109, + range: 2311..2318, value: Some( Name( ExprName { - range: 2108..2109, + range: 2317..2318, id: "x", ctx: Load, }, @@ -2179,7 +2592,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2114..2115, + range: 2323..2324, id: "f", ctx: Store, }, @@ -2190,10 +2603,10 @@ Module( body: [ Expr( StmtExpr { - range: 2117..2120, + range: 2326..2329, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2117..2120, + range: 2326..2329, }, ), }, @@ -2203,22 +2616,22 @@ Module( ), With( StmtWith { - range: 2121..2146, + range: 2330..2355, is_async: false, items: [ WithItem { - range: 2126..2141, + range: 2335..2350, context_expr: Yield( ExprYield { - range: 2127..2135, + range: 2336..2344, value: Some( Tuple( ExprTuple { - range: 2133..2135, + range: 2342..2344, elts: [ Name( ExprName { - range: 2133..2134, + range: 2342..2343, id: "x", ctx: Load, }, @@ -2234,7 +2647,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2140..2141, + range: 2349..2350, id: "f", ctx: Store, }, @@ -2245,10 +2658,10 @@ Module( body: [ Expr( StmtExpr { - range: 2143..2146, + range: 2352..2355, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2143..2146, + range: 2352..2355, }, ), }, @@ -2258,14 +2671,14 @@ Module( ), With( StmtWith { - range: 2532..2544, + range: 2741..2753, is_async: false, items: [ WithItem { - range: 2537..2539, + range: 2746..2748, context_expr: Tuple( ExprTuple { - range: 2537..2539, + range: 2746..2748, elts: [], ctx: Load, parenthesized: true, @@ -2277,10 +2690,10 @@ Module( body: [ Expr( StmtExpr { - range: 2541..2544, + range: 2750..2753, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2541..2544, + range: 2750..2753, }, ), }, @@ -2290,14 +2703,14 @@ Module( ), With( StmtWith { - range: 2545..2562, + range: 2754..2771, is_async: false, items: [ WithItem { - range: 2550..2557, + range: 2759..2766, context_expr: Tuple( ExprTuple { - range: 2550..2552, + range: 2759..2761, elts: [], ctx: Load, parenthesized: true, @@ -2306,7 +2719,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2556..2557, + range: 2765..2766, id: "f", ctx: Store, }, @@ -2317,10 +2730,10 @@ Module( body: [ Expr( StmtExpr { - range: 2559..2562, + range: 2768..2771, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2559..2562, + range: 2768..2771, }, ), }, @@ -2330,28 +2743,28 @@ Module( ), With( StmtWith { - range: 2563..2586, + range: 2772..2795, is_async: false, items: [ WithItem { - range: 2568..2581, + range: 2777..2790, context_expr: Tuple( ExprTuple { - range: 2568..2581, + range: 2777..2790, elts: [ Named( ExprNamed { - range: 2569..2579, + range: 2778..2788, target: Name( ExprName { - range: 2569..2573, + range: 2778..2782, id: "item", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 2577..2579, + range: 2786..2788, value: Int( 42, ), @@ -2370,10 +2783,10 @@ Module( body: [ Expr( StmtExpr { - range: 2583..2586, + range: 2792..2795, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2583..2586, + range: 2792..2795, }, ), }, @@ -2383,18 +2796,18 @@ Module( ), With( StmtWith { - range: 2587..2611, + range: 2796..2820, is_async: false, items: [ WithItem { - range: 2592..2606, + range: 2801..2815, context_expr: Tuple( ExprTuple { - range: 2592..2606, + range: 2801..2815, elts: [ NumberLiteral( ExprNumberLiteral { - range: 2593..2594, + range: 2802..2803, value: Int( 1, ), @@ -2402,17 +2815,17 @@ Module( ), Named( ExprNamed { - range: 2596..2605, + range: 2805..2814, target: Name( ExprName { - range: 2596..2600, + range: 2805..2809, id: "item", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 2604..2605, + range: 2813..2814, value: Int( 2, ), @@ -2431,10 +2844,10 @@ Module( body: [ Expr( StmtExpr { - range: 2608..2611, + range: 2817..2820, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2608..2611, + range: 2817..2820, }, ), }, @@ -2444,28 +2857,28 @@ Module( ), With( StmtWith { - range: 2612..2642, + range: 2821..2851, is_async: false, items: [ WithItem { - range: 2617..2637, + range: 2826..2846, context_expr: Tuple( ExprTuple { - range: 2617..2637, + range: 2826..2846, elts: [ Named( ExprNamed { - range: 2618..2629, + range: 2827..2838, target: Name( ExprName { - range: 2618..2623, + range: 2827..2832, id: "item1", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 2627..2629, + range: 2836..2838, value: Int( 10, ), @@ -2475,7 +2888,7 @@ Module( ), Name( ExprName { - range: 2631..2636, + range: 2840..2845, id: "item2", ctx: Load, }, @@ -2491,10 +2904,10 @@ Module( body: [ Expr( StmtExpr { - range: 2639..2642, + range: 2848..2851, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2639..2642, + range: 2848..2851, }, ), }, @@ -2504,35 +2917,35 @@ Module( ), With( StmtWith { - range: 2643..2684, + range: 2852..2893, is_async: false, items: [ WithItem { - range: 2648..2679, + range: 2857..2888, context_expr: Tuple( ExprTuple { - range: 2648..2674, + range: 2857..2883, elts: [ Name( ExprName { - range: 2649..2654, + range: 2858..2863, id: "item1", ctx: Load, }, ), Named( ExprNamed { - range: 2656..2666, + range: 2865..2875, target: Name( ExprName { - range: 2656..2661, + range: 2865..2870, id: "item2", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 2665..2666, + range: 2874..2875, value: Int( 2, ), @@ -2542,7 +2955,7 @@ Module( ), Name( ExprName { - range: 2668..2673, + range: 2877..2882, id: "item3", ctx: Load, }, @@ -2555,7 +2968,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2678..2679, + range: 2887..2888, id: "f", ctx: Store, }, @@ -2566,10 +2979,10 @@ Module( body: [ Expr( StmtExpr { - range: 2681..2684, + range: 2890..2893, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2681..2684, + range: 2890..2893, }, ), }, @@ -2579,18 +2992,18 @@ Module( ), With( StmtWith { - range: 2685..2707, + range: 2894..2916, is_async: false, items: [ WithItem { - range: 2690..2702, + range: 2899..2911, context_expr: Tuple( ExprTuple { - range: 2690..2697, + range: 2899..2906, elts: [ Name( ExprName { - range: 2691..2695, + range: 2900..2904, id: "item", ctx: Load, }, @@ -2603,7 +3016,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2701..2702, + range: 2910..2911, id: "f", ctx: Store, }, @@ -2614,10 +3027,10 @@ Module( body: [ Expr( StmtExpr { - range: 2704..2707, + range: 2913..2916, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2704..2707, + range: 2913..2916, }, ), }, @@ -2627,21 +3040,21 @@ Module( ), With( StmtWith { - range: 2708..2726, + range: 2917..2935, is_async: false, items: [ WithItem { - range: 2713..2721, + range: 2922..2930, context_expr: Tuple( ExprTuple { - range: 2713..2721, + range: 2922..2930, elts: [ Starred( ExprStarred { - range: 2714..2719, + range: 2923..2928, value: Name( ExprName { - range: 2715..2719, + range: 2924..2928, id: "item", ctx: Load, }, @@ -2660,10 +3073,64 @@ Module( body: [ Expr( StmtExpr { - range: 2723..2726, + range: 2932..2935, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 2932..2935, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 2936..2959, + is_async: false, + items: [ + WithItem { + range: 2941..2954, + context_expr: Tuple( + ExprTuple { + range: 2941..2949, + elts: [ + Starred( + ExprStarred { + range: 2942..2947, + value: Name( + ExprName { + range: 2943..2947, + id: "item", + ctx: Load, + }, + ), + ctx: Load, + }, + ), + ], + ctx: Load, + parenthesized: true, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 2953..2954, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Expr( + StmtExpr { + range: 2956..2959, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2723..2726, + range: 2956..2959, }, ), }, @@ -2673,25 +3140,25 @@ Module( ), With( StmtWith { - range: 2727..2756, + range: 2960..2989, is_async: false, items: [ WithItem { - range: 2732..2751, + range: 2965..2984, context_expr: Tuple( ExprTuple { - range: 2732..2746, + range: 2965..2979, elts: [ Name( ExprName { - range: 2733..2738, + range: 2966..2971, id: "item1", ctx: Load, }, ), Name( ExprName { - range: 2740..2745, + range: 2973..2978, id: "item2", ctx: Load, }, @@ -2704,7 +3171,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2750..2751, + range: 2983..2984, id: "f", ctx: Store, }, @@ -2715,10 +3182,10 @@ Module( body: [ Expr( StmtExpr { - range: 2753..2756, + range: 2986..2989, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2753..2756, + range: 2986..2989, }, ), }, @@ -2728,25 +3195,25 @@ Module( ), With( StmtWith { - range: 2757..2787, + range: 2990..3020, is_async: false, items: [ WithItem { - range: 2762..2782, + range: 2995..3015, context_expr: Tuple( ExprTuple { - range: 2762..2777, + range: 2995..3010, elts: [ Name( ExprName { - range: 2763..2768, + range: 2996..3001, id: "item1", ctx: Load, }, ), Name( ExprName { - range: 2770..2775, + range: 3003..3008, id: "item2", ctx: Load, }, @@ -2759,7 +3226,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2781..2782, + range: 3014..3015, id: "f", ctx: Store, }, @@ -2770,10 +3237,10 @@ Module( body: [ Expr( StmtExpr { - range: 2784..2787, + range: 3017..3020, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2784..2787, + range: 3017..3020, }, ), }, @@ -2783,25 +3250,25 @@ Module( ), With( StmtWith { - range: 2788..2819, + range: 3021..3052, is_async: false, items: [ WithItem { - range: 2793..2807, + range: 3026..3040, context_expr: Tuple( ExprTuple { - range: 2793..2807, + range: 3026..3040, elts: [ Name( ExprName { - range: 2794..2799, + range: 3027..3032, id: "item1", ctx: Load, }, ), Name( ExprName { - range: 2801..2806, + range: 3034..3039, id: "item2", ctx: Load, }, @@ -2814,10 +3281,10 @@ Module( optional_vars: None, }, WithItem { - range: 2809..2814, + range: 3042..3047, context_expr: Name( ExprName { - range: 2809..2814, + range: 3042..3047, id: "item3", ctx: Load, }, @@ -2828,10 +3295,10 @@ Module( body: [ Expr( StmtExpr { - range: 2816..2819, + range: 3049..3052, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2816..2819, + range: 3049..3052, }, ), }, @@ -2841,29 +3308,29 @@ Module( ), With( StmtWith { - range: 2820..2858, + range: 3053..3091, is_async: false, items: [ WithItem { - range: 2825..2853, + range: 3058..3086, context_expr: Tuple( ExprTuple { - range: 2825..2848, + range: 3058..3081, elts: [ Tuple( ExprTuple { - range: 2826..2840, + range: 3059..3073, elts: [ Name( ExprName { - range: 2827..2832, + range: 3060..3065, id: "item1", ctx: Load, }, ), Name( ExprName { - range: 2834..2839, + range: 3067..3072, id: "item2", ctx: Load, }, @@ -2875,7 +3342,7 @@ Module( ), Name( ExprName { - range: 2842..2847, + range: 3075..3080, id: "item3", ctx: Load, }, @@ -2888,7 +3355,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2852..2853, + range: 3085..3086, id: "f", ctx: Store, }, @@ -2899,10 +3366,10 @@ Module( body: [ Expr( StmtExpr { - range: 2855..2858, + range: 3088..3091, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2855..2858, + range: 3088..3091, }, ), }, @@ -2912,18 +3379,18 @@ Module( ), With( StmtWith { - range: 2859..2905, + range: 3092..3138, is_async: false, items: [ WithItem { - range: 2864..2872, + range: 3097..3105, context_expr: Tuple( ExprTuple { - range: 2864..2872, + range: 3097..3105, elts: [ Name( ExprName { - range: 2865..2870, + range: 3098..3103, id: "item1", ctx: Load, }, @@ -2936,10 +3403,10 @@ Module( optional_vars: None, }, WithItem { - range: 2874..2879, + range: 3107..3112, context_expr: Name( ExprName { - range: 2874..2879, + range: 3107..3112, id: "item2", ctx: Load, }, @@ -2947,21 +3414,21 @@ Module( optional_vars: None, }, WithItem { - range: 2881..2900, + range: 3114..3133, context_expr: Tuple( ExprTuple { - range: 2881..2895, + range: 3114..3128, elts: [ Name( ExprName { - range: 2882..2887, + range: 3115..3120, id: "item3", ctx: Load, }, ), Name( ExprName { - range: 2889..2894, + range: 3122..3127, id: "item4", ctx: Load, }, @@ -2974,7 +3441,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2899..2900, + range: 3132..3133, id: "f", ctx: Store, }, @@ -2985,10 +3452,10 @@ Module( body: [ Expr( StmtExpr { - range: 2902..2905, + range: 3135..3138, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2902..2905, + range: 3135..3138, }, ), }, @@ -2998,25 +3465,25 @@ Module( ), With( StmtWith { - range: 2906..2949, + range: 3139..3182, is_async: false, items: [ WithItem { - range: 2911..2931, + range: 3144..3164, context_expr: Tuple( ExprTuple { - range: 2911..2925, + range: 3144..3158, elts: [ Name( ExprName { - range: 2912..2917, + range: 3145..3150, id: "item1", ctx: Load, }, ), Name( ExprName { - range: 2919..2924, + range: 3152..3157, id: "item2", ctx: Load, }, @@ -3029,7 +3496,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2929..2931, + range: 3162..3164, id: "f1", ctx: Store, }, @@ -3037,10 +3504,10 @@ Module( ), }, WithItem { - range: 2933..2944, + range: 3166..3177, context_expr: Name( ExprName { - range: 2933..2938, + range: 3166..3171, id: "item3", ctx: Load, }, @@ -3048,7 +3515,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 2942..2944, + range: 3175..3177, id: "f2", ctx: Store, }, @@ -3059,10 +3526,10 @@ Module( body: [ Expr( StmtExpr { - range: 2946..2949, + range: 3179..3182, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2946..2949, + range: 3179..3182, }, ), }, @@ -3072,28 +3539,28 @@ Module( ), With( StmtWith { - range: 2950..2975, + range: 3183..3208, is_async: false, items: [ WithItem { - range: 2955..2970, + range: 3188..3203, context_expr: Tuple( ExprTuple { - range: 2955..2970, + range: 3188..3203, elts: [ Name( ExprName { - range: 2956..2961, + range: 3189..3194, id: "item1", ctx: Load, }, ), Starred( ExprStarred { - range: 2963..2969, + range: 3196..3202, value: Name( ExprName { - range: 2964..2969, + range: 3197..3202, id: "item2", ctx: Load, }, @@ -3112,10 +3579,10 @@ Module( body: [ Expr( StmtExpr { - range: 2972..2975, + range: 3205..3208, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 2972..2975, + range: 3205..3208, }, ), }, @@ -3125,28 +3592,28 @@ Module( ), With( StmtWith { - range: 2976..3006, + range: 3209..3239, is_async: false, items: [ WithItem { - range: 2981..3001, + range: 3214..3234, context_expr: Tuple( ExprTuple { - range: 2981..2996, + range: 3214..3229, elts: [ Name( ExprName { - range: 2982..2987, + range: 3215..3220, id: "item1", ctx: Load, }, ), Starred( ExprStarred { - range: 2989..2995, + range: 3222..3228, value: Name( ExprName { - range: 2990..2995, + range: 3223..3228, id: "item2", ctx: Load, }, @@ -3162,7 +3629,7 @@ Module( optional_vars: Some( Name( ExprName { - range: 3000..3001, + range: 3233..3234, id: "f", ctx: Store, }, @@ -3173,10 +3640,10 @@ Module( body: [ Expr( StmtExpr { - range: 3003..3006, + range: 3236..3239, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 3003..3006, + range: 3236..3239, }, ), }, @@ -3186,28 +3653,28 @@ Module( ), With( StmtWith { - range: 3007..3038, + range: 3240..3271, is_async: false, items: [ WithItem { - range: 3012..3033, + range: 3245..3266, context_expr: Tuple( ExprTuple { - range: 3012..3033, + range: 3245..3266, elts: [ Named( ExprNamed { - range: 3013..3024, + range: 3246..3257, target: Name( ExprName { - range: 3013..3018, + range: 3246..3251, id: "item1", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 3022..3024, + range: 3255..3257, value: Int( 10, ), @@ -3217,10 +3684,10 @@ Module( ), Starred( ExprStarred { - range: 3026..3032, + range: 3259..3265, value: Name( ExprName { - range: 3027..3032, + range: 3260..3265, id: "item2", ctx: Load, }, @@ -3239,10 +3706,10 @@ Module( body: [ Expr( StmtExpr { - range: 3035..3038, + range: 3268..3271, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 3035..3038, + range: 3268..3271, }, ), }, @@ -3252,28 +3719,28 @@ Module( ), With( StmtWith { - range: 3039..3072, + range: 3272..3305, is_async: false, items: [ WithItem { - range: 3044..3067, + range: 3277..3300, context_expr: Tuple( ExprTuple { - range: 3044..3067, + range: 3277..3300, elts: [ Named( ExprNamed { - range: 3046..3057, + range: 3279..3290, target: Name( ExprName { - range: 3046..3051, + range: 3279..3284, id: "item1", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 3055..3057, + range: 3288..3290, value: Int( 10, ), @@ -3283,10 +3750,10 @@ Module( ), Starred( ExprStarred { - range: 3060..3066, + range: 3293..3299, value: Name( ExprName { - range: 3061..3066, + range: 3294..3299, id: "item2", ctx: Load, }, @@ -3305,10 +3772,10 @@ Module( body: [ Expr( StmtExpr { - range: 3069..3072, + range: 3302..3305, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 3069..3072, + range: 3302..3305, }, ), }, @@ -3318,47 +3785,47 @@ Module( ), With( StmtWith { - range: 3277..3309, + range: 3510..3542, is_async: false, items: [ WithItem { - range: 3282..3304, + range: 3515..3537, context_expr: Generator( ExprGenerator { - range: 3282..3304, + range: 3515..3537, elt: Name( ExprName { - range: 3283..3284, + range: 3516..3517, id: "x", ctx: Load, }, ), generators: [ Comprehension { - range: 3285..3303, + range: 3518..3536, target: Name( ExprName { - range: 3289..3290, + range: 3522..3523, id: "x", ctx: Store, }, ), iter: Call( ExprCall { - range: 3294..3303, + range: 3527..3536, func: Name( ExprName { - range: 3294..3299, + range: 3527..3532, id: "range", ctx: Load, }, ), arguments: Arguments { - range: 3299..3303, + range: 3532..3536, args: [ NumberLiteral( ExprNumberLiteral { - range: 3300..3302, + range: 3533..3535, value: Int( 10, ), @@ -3382,10 +3849,10 @@ Module( body: [ Expr( StmtExpr { - range: 3306..3309, + range: 3539..3542, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 3306..3309, + range: 3539..3542, }, ), }, @@ -3395,47 +3862,47 @@ Module( ), With( StmtWith { - range: 3310..3348, + range: 3543..3581, is_async: false, items: [ WithItem { - range: 3315..3343, + range: 3548..3576, context_expr: Generator( ExprGenerator { - range: 3315..3343, + range: 3548..3576, elt: Name( ExprName { - range: 3316..3317, + range: 3549..3550, id: "x", ctx: Load, }, ), generators: [ Comprehension { - range: 3318..3342, + range: 3551..3575, target: Name( ExprName { - range: 3328..3329, + range: 3561..3562, id: "x", ctx: Store, }, ), iter: Call( ExprCall { - range: 3333..3342, + range: 3566..3575, func: Name( ExprName { - range: 3333..3338, + range: 3566..3571, id: "range", ctx: Load, }, ), arguments: Arguments { - range: 3338..3342, + range: 3571..3575, args: [ NumberLiteral( ExprNumberLiteral { - range: 3339..3341, + range: 3572..3574, value: Int( 10, ), @@ -3459,10 +3926,10 @@ Module( body: [ Expr( StmtExpr { - range: 3345..3348, + range: 3578..3581, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 3345..3348, + range: 3578..3581, }, ), }, @@ -3472,47 +3939,47 @@ Module( ), With( StmtWith { - range: 3349..3387, + range: 3582..3620, is_async: false, items: [ WithItem { - range: 3354..3376, + range: 3587..3609, context_expr: Generator( ExprGenerator { - range: 3354..3376, + range: 3587..3609, elt: Name( ExprName { - range: 3355..3356, + range: 3588..3589, id: "x", ctx: Load, }, ), generators: [ Comprehension { - range: 3357..3375, + range: 3590..3608, target: Name( ExprName { - range: 3361..3362, + range: 3594..3595, id: "x", ctx: Store, }, ), iter: Call( ExprCall { - range: 3366..3375, + range: 3599..3608, func: Name( ExprName { - range: 3366..3371, + range: 3599..3604, id: "range", ctx: Load, }, ), arguments: Arguments { - range: 3371..3375, + range: 3604..3608, args: [ NumberLiteral( ExprNumberLiteral { - range: 3372..3374, + range: 3605..3607, value: Int( 10, ), @@ -3533,10 +4000,10 @@ Module( optional_vars: None, }, WithItem { - range: 3378..3382, + range: 3611..3615, context_expr: Name( ExprName { - range: 3378..3382, + range: 3611..3615, id: "item", ctx: Load, }, @@ -3547,10 +4014,10 @@ Module( body: [ Expr( StmtExpr { - range: 3384..3387, + range: 3617..3620, value: EllipsisLiteral( ExprEllipsisLiteral { - range: 3384..3387, + range: 3617..3620, }, ), }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap index 3f2bcd04c0cca..cbd06ce99322e 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap @@ -7,28 +7,264 @@ input_file: crates/ruff_python_parser/resources/valid/statement/with.py ``` Module( ModModule { - range: 0..22, + range: 0..361, body: [ With( StmtWith { - range: 0..21, + range: 137..151, is_async: false, items: [ WithItem { - range: 5..11, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, + range: 142..146, + context_expr: Name( + ExprName { + range: 142..146, + id: "item", + ctx: Load, + }, + ), + optional_vars: None, + }, + ], + body: [ + Expr( + StmtExpr { + range: 148..151, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 148..151, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 152..171, + is_async: false, + items: [ + WithItem { + range: 157..166, + context_expr: Name( + ExprName { + range: 157..161, + id: "item", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 165..166, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Expr( + StmtExpr { + range: 168..171, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 168..171, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 172..194, + is_async: false, + items: [ + WithItem { + range: 177..182, + context_expr: Name( + ExprName { + range: 177..182, + id: "item1", + ctx: Load, + }, + ), + optional_vars: None, + }, + WithItem { + range: 184..189, + context_expr: Name( + ExprName { + range: 184..189, + id: "item2", + ctx: Load, + }, + ), + optional_vars: None, + }, + ], + body: [ + Expr( + StmtExpr { + range: 191..194, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 191..194, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 195..229, + is_async: false, + items: [ + WithItem { + range: 200..211, + context_expr: Name( + ExprName { + range: 200..205, + id: "item1", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 209..211, + id: "f1", + ctx: Store, + }, + ), + ), + }, + WithItem { + range: 213..224, + context_expr: Name( + ExprName { + range: 213..218, + id: "item2", + ctx: Load, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 222..224, + id: "f2", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Expr( + StmtExpr { + range: 226..229, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 226..229, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 231..257, + is_async: false, + items: [ + WithItem { + range: 236..252, + context_expr: If( + ExprIf { + range: 236..252, + test: BooleanLiteral( + ExprBooleanLiteral { + range: 241..245, + value: true, + }, + ), + body: Name( + ExprName { + range: 236..237, + id: "x", + ctx: Load, + }, + ), + orelse: Name( + ExprName { + range: 251..252, + id: "y", + ctx: Load, + }, + ), + }, + ), + optional_vars: None, + }, + ], + body: [ + Expr( + StmtExpr { + range: 254..257, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 254..257, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 258..289, + is_async: false, + items: [ + WithItem { + range: 263..284, + context_expr: If( + ExprIf { + range: 263..279, + test: BooleanLiteral( + ExprBooleanLiteral { + range: 268..272, + value: true, + }, + ), + body: Name( + ExprName { + range: 263..264, + id: "x", + ctx: Load, + }, + ), + orelse: Name( + ExprName { + range: 278..279, + id: "y", + ctx: Load, + }, ), }, ), optional_vars: Some( Name( ExprName { - range: 10..11, - id: "x", + range: 283..284, + id: "f", ctx: Store, }, ), @@ -36,9 +272,122 @@ Module( }, ], body: [ - Pass( - StmtPass { - range: 17..21, + Expr( + StmtExpr { + range: 286..289, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 286..289, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 313..334, + is_async: false, + items: [ + WithItem { + range: 318..329, + context_expr: Call( + ExprCall { + range: 318..324, + func: Name( + ExprName { + range: 318..322, + id: "open", + ctx: Load, + }, + ), + arguments: Arguments { + range: 322..324, + args: [], + keywords: [], + }, + }, + ), + optional_vars: Some( + Name( + ExprName { + range: 328..329, + id: "f", + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Expr( + StmtExpr { + range: 331..334, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 331..334, + }, + ), + }, + ), + ], + }, + ), + With( + StmtWith { + range: 335..361, + is_async: false, + items: [ + WithItem { + range: 340..356, + context_expr: Call( + ExprCall { + range: 340..346, + func: Name( + ExprName { + range: 340..344, + id: "open", + ctx: Load, + }, + ), + arguments: Arguments { + range: 344..346, + args: [], + keywords: [], + }, + }, + ), + optional_vars: Some( + Attribute( + ExprAttribute { + range: 350..356, + value: Name( + ExprName { + range: 350..351, + id: "f", + ctx: Load, + }, + ), + attr: Identifier { + id: "attr", + range: 352..356, + }, + ctx: Store, + }, + ), + ), + }, + ], + body: [ + Expr( + StmtExpr { + range: 358..361, + value: EllipsisLiteral( + ExprEllipsisLiteral { + range: 358..361, + }, + ), }, ), ],