Support `TypeAliasType` explicit call
The implementation turned out to be quite simple for the common cases.
Note: Right now there's no check that type_params= is correct, I am not sure that this is even required for a type-checker (in any case, this can and should be done in a follow-up PR)
Refs https://github.com/python/mypy/issues/16614
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅
I will try to find how to fix typevar representation change without code modifications, I think that this has to do with my typing fixtures.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅
One big advantage of X = TypeAliasType("X", ...) over X: TypeAlias = ... is that you can choose the order of the type parameters:
from typing import TypeVar
from typing_extensions import TypeAliasType
K = TypeVar("K")
V = TypeVar("V")
InvertedDict = TypeAliasType("InvertedDict", dict[K, V], type_params=(V, K))
def f(x: InvertedDict[int, str]) -> None:
reveal_type(x)
pyright correctly reveals the type as dict[str, int] (i.e., inverted), but this branch reveals:
main.py:10: note: Revealed type is "builtins.dict[builtins.int, builtins.str]"
I don't think we should claim support for TypeAliasType without checking the type_params. Explicit type_params are the main differentiating factor that sets the new syntax apart.
Hello @sobolevn, I'd like to try and finish up this PR if that's OK with you.
@hamdanal please, go ahead :) I forgot about it, sorry.
Merged #16926 instead, thanks for your work here!