Conversation

erikkemperman

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.

@github-actionsGitHub Actions

This comment has been minimized.

@erikkemperman

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.

@github-actionsGitHub Actions

This comment has been minimized.

@sterliakov

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)

@github-actionsGitHub Actions

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

@erikkemperman

@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 . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

Allow TypeVarTuple as type argument for subclasses of generic TypedDict