Fix range of unparenthesized tuple subject in match statement (#8101)

## Summary

This was just a bug in the parser ranges, probably since it was
initially implemented. Given `match n % 3, n % 5: ...`, the "subject"
(i.e., the tuple of two binary operators) was using the entire range of
the `match` statement.

Closes https://github.com/astral-sh/ruff/issues/8091.

## Test Plan

`cargo test`
This commit is contained in:
Charlie Marsh 2023-10-22 16:58:33 -07:00 committed by GitHub
parent 95702e408f
commit d6a4283003
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 2763 additions and 2369 deletions

View file

@ -445,4 +445,153 @@ expression: parse_ast
],
},
),
Match(
StmtMatch {
range: 298..332,
subject: Tuple(
ExprTuple {
range: 304..306,
elts: [
Name(
ExprName {
range: 304..305,
id: "x",
ctx: Load,
},
),
],
ctx: Load,
},
),
cases: [
MatchCase {
range: 312..332,
pattern: MatchAs(
PatternMatchAs {
range: 317..318,
pattern: None,
name: Some(
Identifier {
id: "z",
range: 317..318,
},
),
},
),
guard: None,
body: [
Pass(
StmtPass {
range: 328..332,
},
),
],
},
],
},
),
Match(
StmtMatch {
range: 333..369,
subject: Tuple(
ExprTuple {
range: 339..343,
elts: [
Name(
ExprName {
range: 339..340,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 342..343,
id: "y",
ctx: Load,
},
),
],
ctx: Load,
},
),
cases: [
MatchCase {
range: 349..369,
pattern: MatchAs(
PatternMatchAs {
range: 354..355,
pattern: None,
name: Some(
Identifier {
id: "z",
range: 354..355,
},
),
},
),
guard: None,
body: [
Pass(
StmtPass {
range: 365..369,
},
),
],
},
],
},
),
Match(
StmtMatch {
range: 370..407,
subject: Tuple(
ExprTuple {
range: 376..381,
elts: [
Name(
ExprName {
range: 376..377,
id: "x",
ctx: Load,
},
),
Name(
ExprName {
range: 379..380,
id: "y",
ctx: Load,
},
),
],
ctx: Load,
},
),
cases: [
MatchCase {
range: 387..407,
pattern: MatchAs(
PatternMatchAs {
range: 392..393,
pattern: None,
name: Some(
Identifier {
id: "z",
range: 392..393,
},
),
},
),
guard: None,
body: [
Pass(
StmtPass {
range: 403..407,
},
),
],
},
],
},
),
]

View file

@ -3449,10 +3449,18 @@ expression: parse_ast
Match(
StmtMatch {
range: 2661..2697,
subject: Name(
ExprName {
range: 2667..2668,
id: "x",
subject: Tuple(
ExprTuple {
range: 2667..2669,
elts: [
Name(
ExprName {
range: 2667..2668,
id: "x",
ctx: Load,
},
),
],
ctx: Load,
},
),
@ -3512,7 +3520,7 @@ expression: parse_ast
range: 2720..2760,
subject: Tuple(
ExprTuple {
range: 2720..2760,
range: 2726..2730,
elts: [
Name(
ExprName {
@ -3598,23 +3606,31 @@ expression: parse_ast
Match(
StmtMatch {
range: 2783..2829,
subject: NamedExpr(
ExprNamedExpr {
range: 2789..2795,
target: Name(
ExprName {
range: 2789..2790,
id: "w",
ctx: Store,
},
),
value: Name(
ExprName {
range: 2794..2795,
id: "x",
ctx: Load,
},
),
subject: Tuple(
ExprTuple {
range: 2789..2796,
elts: [
NamedExpr(
ExprNamedExpr {
range: 2789..2795,
target: Name(
ExprName {
range: 2789..2790,
id: "w",
ctx: Store,
},
),
value: Name(
ExprName {
range: 2794..2795,
id: "x",
ctx: Load,
},
),
},
),
],
ctx: Load,
},
),
cases: [