Skip to content

Report error when type alias has multiple TypeVarTuples (PEP 695) - #20554

Closed
aviralgarg05 wants to merge 4 commits into
python:masterfrom
aviralgarg05:fix-issue-20544-multiple-typevartuple-in-type-alias
Closed

aviralgarg05 wants to merge 4 commits into
python:masterfrom
aviralgarg05:fix-issue-20544-multiple-typevartuple-in-type-alias

Conversation

@aviralgarg05

Copy link
Copy Markdown

Report error when type alias has multiple TypeVarTuples (PEP 695)

When defining a type alias using the PEP 695 syntax with multiple TypeVarTuple-based type parameters (e.g., type TA[*Ts1, *Ts2] = ...), mypy now reports an error at definition time rather than only when the alias is used.

This is consistent with how mypy handles classes with multiple TypeVarTuples and matches the behavior of other type checkers like pyright and pyrefly.

Fixes #20544.

When defining a type alias using the PEP 695 syntax with multiple
TypeVarTuple-based type parameters (e.g., `type TA[*Ts1, *Ts2] = ...`),
mypy now reports an error at definition time rather than only when
the alias is used.

This is consistent with how mypy handles classes with multiple
TypeVarTuples and matches the behavior of other type checkers like
pyright and pyrefly.

Fixes python#20544.
@github-actions

This comment has been minimized.

@A5rocks

A5rocks commented Jan 13, 2026

Copy link
Copy Markdown
Collaborator

Could you support old-style type aliases too? The linked issue has that too, simply uncomment it.

@github-actions

This comment has been minimized.

Comment thread mypy/semanal.py Resolved
Comment thread mypy/semanal.py Resolved
@A5rocks

A5rocks commented Jan 13, 2026

Copy link
Copy Markdown
Collaborator

CI failures look like it's because testVariadicAliasMultipleUnpacks's output changed. I think the new output is more accurate (there's two issues: 1) the alias requires 2 typevartuples to use, 2) the type has 2 Unpacks within. Therefore reporting 2 errors is good, actually).

@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. ✅

@aviralgarg05

Copy link
Copy Markdown
Author

Closing this because current master now includes #22216, which centralizes multiple-TypeVarTuple validation and covers both old and PEP 695 alias syntax. That supersedes this implementation, so rebasing it would duplicate the newer fix. Thanks again for the earlier review.

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.

mypy should give error at the timing when the type alias set multiple TypeVarTuple-based type parameters is defined but not used

2 participants