Skip to content

Fix crash on Unpack used without arguments in class bases#21470

Merged
ilevkivskyi merged 1 commit into
python:masterfrom
SAY-5:fix-unpack-no-args
May 12, 2026
Merged

Fix crash on Unpack used without arguments in class bases#21470
ilevkivskyi merged 1 commit into
python:masterfrom
SAY-5:fix-unpack-no-args

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented May 12, 2026

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.

analyze_unbound_tvar accessed t.args[0] unconditionally when the base
was Unpack with no arguments (e.g. Protocol[Unpack]), raising IndexError.
Return None in that case so a proper 'Free type variable expected' error
is reported instead.

Fixes python#21467
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Copy Markdown
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, thanks!

@ilevkivskyi ilevkivskyi merged commit d62a508 into python:master May 12, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError: tuple index out of range in analyze_unbound_tvar

2 participants