Repository navigation
Commit 27291ca
authored
Fix crash in match statement when subject expression have unpacked tuple (python#21989)
Fixes python#21468
Match subject expressions containing an unpacked tuple crash mypy. This
looks like a regression introduced by
python#16905, which asserts that the
subject expression's items line up one-to-one with its inferred type's
items. well, because starred subject expression is flattened out, the
type ends up with more items than the expression.
```python
foo: int
bar: tuple[int, int]
match foo, *bar: # this `*bar` gets flattened, foo -> int, bar -> int, int.
# [int, int, int] But, the expression only has two items (foo and *bar), hence we crash.
case _: pass
```
This PR is trivial because it returns early instead of asserting, to
prevent the crash. Unfortunately, this doesn't preserve narrowing for
unpacked tuples in the way python#16905 seems to have been heading toward.
I've kept this PR scoped to just preventing this crash; narrowing can
(probably will, I don't think I have the bandwidth for it right now
:sweat_smile: ) be handled in a separate PR.1 parent 51258d3 commit 27291ca
2 files changed
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6124 | 6124 | | |
6125 | 6125 | | |
6126 | 6126 | | |
| 6127 | + | |
| 6128 | + | |
| 6129 | + | |
| 6130 | + | |
| 6131 | + | |
| 6132 | + | |
6127 | 6133 | | |
6128 | 6134 | | |
6129 | 6135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
512 | 526 | | |
513 | 527 | | |
514 | 528 | | |
| |||
0 commit comments