Skip to content

Allow TypeVarTuple arguments to subclasses of generic TypedDict #19234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

erikkemperman
Copy link
Contributor

@erikkemperman erikkemperman commented Jun 4, 2025

Fixes #16975
Supersedes #16977

Allows TypeVarTuples as type argument for subclasses of generic TypedDicts.

Since (1) TypedDict became generic and (2) TypeVarTuple was introduced, mypy now supports creating generic typed dictionaries with variadic type arguments. However, things went wrong when deriving a subclass from such a generic typeddict.

Full disclosure: I submitted an earlier PR for this issue, but it's been a while. Earlier I wasn't 100% sure about one minor aspect of the changes I made, but in the mean time the context has changed to the point that that aspect is no longer relevant.

For tests, I started with a copy of an existing one from test-data/unit/check-typevar-tuple.test, and added two subclasses: one which just passes a TypeVarTuple generic type parameter up to the base class, and another which passes a TypeVarTuple and adds a regular TypeVar argument.

I did this all of this twice: once using the Unpack[Ts] syntax and once using the *Ts syntax.

This comment has been minimized.

@erikkemperman
Copy link
Contributor Author

erikkemperman commented Jun 4, 2025

Apologies, I removed the *Ts syntax unit test for now, obviously that doesn't work for older Python versions... Should perhaps live in check-python311.test? I'm still not entirely clear on the logic behind which test goes where, to be honest.

This comment has been minimized.

@sterliakov
Copy link
Collaborator

Should perhaps live in check-python311.test

Yes, every test that depends on python version higher than minimal supported version (3.9 now) should live in check-python*.test files (matching the minimal version where such syntax is supported)

Copy link
Contributor

github-actions bot commented Jun 5, 2025

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

@erikkemperman
Copy link
Contributor Author

@sterliakov Thanks for taking a look, and for the suggestion. I've moved the tests using *Ts syntax into check-python311.test.

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.

Allow TypeVarTuple as type argument for subclasses of generic TypedDict
2 participants