Commit d62a508
authored
Fix crash on Unpack used without arguments in class bases (#21470)
Fixes #21467.
`analyze_unbound_tvar` accessed `t.args[0]` unconditionally when a class
base was `Unpack` with no arguments (e.g. `class C(Protocol[Unpack]):
...`), raising `IndexError: tuple index out of range` during semantic
analysis.
This adds a guard returning `None` in that case, so the existing "Free
type variable expected in Protocol[...]" error is reported instead of
crashing.
Added a regression test in `check-typevar-tuple.test`.1 parent e53693b commit d62a508
2 files changed
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2403 | 2403 | | |
2404 | 2404 | | |
2405 | 2405 | | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
2406 | 2409 | | |
2407 | 2410 | | |
2408 | 2411 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2765 | 2765 | | |
2766 | 2766 | | |
2767 | 2767 | | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
0 commit comments