Fix parsing of tuple with named expression as context manager

Because the ‘with’ item grammar disallows named expressions, CPython
parses ‘with (a := 0, b := 1):’ as a tuple rather than two ‘with’
items.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2022-12-24 11:21:16 -08:00
parent c387b5d523
commit 1fdfa5fe1b
2 changed files with 141 additions and 116 deletions

View file

@ -1792,106 +1792,121 @@ expression: "parse_program(source, \"<test>\").unwrap()"
context_expr: Located {
location: Location {
row: 21,
column: 6,
column: 5,
},
end_location: Some(
Location {
row: 21,
column: 12,
column: 21,
},
),
custom: (),
node: NamedExpr {
target: Located {
location: Location {
row: 21,
column: 6,
},
end_location: Some(
Location {
node: Tuple {
elts: [
Located {
location: Location {
row: 21,
column: 12,
column: 6,
},
),
custom: (),
node: Name {
id: "a",
ctx: Store,
},
},
value: Located {
location: Location {
row: 21,
column: 11,
},
end_location: Some(
Location {
row: 21,
column: 12,
},
),
custom: (),
node: Constant {
value: Int(
0,
end_location: Some(
Location {
row: 21,
column: 12,
},
),
kind: None,
},
},
},
},
optional_vars: None,
},
Withitem {
context_expr: Located {
location: Location {
row: 21,
column: 14,
},
end_location: Some(
Location {
row: 21,
column: 20,
},
),
custom: (),
node: NamedExpr {
target: Located {
location: Location {
row: 21,
column: 14,
},
end_location: Some(
Location {
row: 21,
column: 20,
custom: (),
node: NamedExpr {
target: Located {
location: Location {
row: 21,
column: 6,
},
end_location: Some(
Location {
row: 21,
column: 12,
},
),
custom: (),
node: Name {
id: "a",
ctx: Store,
},
},
value: Located {
location: Location {
row: 21,
column: 11,
},
end_location: Some(
Location {
row: 21,
column: 12,
},
),
custom: (),
node: Constant {
value: Int(
0,
),
kind: None,
},
},
},
),
custom: (),
node: Name {
id: "b",
ctx: Store,
},
},
value: Located {
location: Location {
row: 21,
column: 19,
},
end_location: Some(
Location {
Located {
location: Location {
row: 21,
column: 20,
column: 14,
},
),
custom: (),
node: Constant {
value: Int(
1,
end_location: Some(
Location {
row: 21,
column: 20,
},
),
kind: None,
custom: (),
node: NamedExpr {
target: Located {
location: Location {
row: 21,
column: 14,
},
end_location: Some(
Location {
row: 21,
column: 20,
},
),
custom: (),
node: Name {
id: "b",
ctx: Store,
},
},
value: Located {
location: Location {
row: 21,
column: 19,
},
end_location: Some(
Location {
row: 21,
column: 20,
},
),
custom: (),
node: Constant {
value: Int(
1,
),
kind: None,
},
},
},
},
},
],
ctx: Load,
},
},
optional_vars: None,