@@ -1085,17 +1085,18 @@ T1 = T2 = TypeAliasType("T", int)
10851085t1: T1 # E: Variable "__main__.T1" is not valid as a type \
10861086 # N: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
10871087
1088- T3 = TypeAliasType("T3", -1)
1089- t3: T3 # E: Variable "__main__.T3" is not valid as a type \
1090- # N: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs- type-aliases
1088+ T3 = TypeAliasType("T3", -1) # E: Invalid type: try using Literal[-1] instead?
1089+ t3: T3
1090+ reveal_type(t3) # N: Revealed type is "Any"
10911091[builtins fixtures/tuple.pyi]
10921092
10931093[case testTypeAliasTypeGeneric]
1094- from typing_extensions import TypeAliasType, TypeVarTuple, ParamSpec
1095- from typing import Callable, Dict, TypeVar, Tuple , Unpack
1094+ from typing import Callable, Dict, Generic, TypeVar, Tuple
1095+ from typing_extensions import TypeAliasType, TypeVarTuple, ParamSpec , Unpack
10961096
10971097K = TypeVar('K')
10981098V = TypeVar('V')
1099+ T = TypeVar('T')
10991100Ts = TypeVarTuple("Ts")
11001101Ts1 = TypeVarTuple("Ts1")
11011102P = ParamSpec("P")
@@ -1123,14 +1124,20 @@ def g(x: int, y: float) -> int: return 1
11231124xp1: ParamAlias[str, float] = f
11241125xp2: ParamAlias[str, float] = g # E: Incompatible types in assignment (expression has type "Callable[[int, float], int]", variable has type "Callable[[str, float], int]")
11251126xp3: ParamAlias[str, float] = lambda x, y: 1
1127+
1128+ class G(Generic[P, T]): ...
1129+ ParamAlias2 = TypeAliasType("ParamAlias2", G[P, T], type_params=(P, T))
1130+ xp: ParamAlias2[[int], str]
1131+ reveal_type(xp) # N: Revealed type is "__main__.G[[builtins.int], builtins.str]"
11261132[builtins fixtures/dict.pyi]
11271133
11281134[case testTypeAliasTypeInvalidGeneric]
11291135from typing_extensions import TypeAliasType, TypeVarTuple, ParamSpec
1130- from typing import Dict, TypeVar, Tuple, Unpack
1136+ from typing import Callable, Dict, Generic , TypeVar, Tuple, Unpack
11311137
11321138K = TypeVar('K')
11331139V = TypeVar('V')
1140+ T = TypeVar('T')
11341141Ts = TypeVarTuple("Ts")
11351142Ts1 = TypeVarTuple("Ts1")
11361143P = ParamSpec("P")
@@ -1139,7 +1146,7 @@ Ta1 = TypeAliasType("Ta1", int, type_params=K) # E: Tuple literal expected as t
11391146
11401147Ta2 = TypeAliasType("Ta2", int, type_params=(None,)) # E: Free type variable expected in type_params argument to TypeAliasType
11411148
1142- Ta3 = TypeAliasType("Ta3", Dict[K, V], type_params=(V,)) # E: Can't use bound type variable "K" to define generic alias
1149+ Ta3 = TypeAliasType("Ta3", Dict[K, V], type_params=(V,)) # E: Type variable "K" is not included in type_params
11431150partially_generic1: Ta3[int] = {"a": 1}
11441151reveal_type(partially_generic1) # N: Revealed type is "builtins.dict[Any, builtins.int]"
11451152partially_generic2: Ta3[int] = {1: "a"} # E: Dict entry 0 has incompatible type "int": "str"; expected "Any": "int"
@@ -1148,6 +1155,25 @@ Ta4 = TypeAliasType("Ta4", Tuple[Unpack[Ts]], type_params=(Ts, Ts1)) # E: Can o
11481155
11491156Ta5 = TypeAliasType("Ta5", Dict) # Unlike old style aliases, this is not generic
11501157non_generic_dict: Ta5[int, str] # E: Bad number of arguments for type alias, expected 0, given 2
1158+ reveal_type(non_generic_dict) # N: Revealed type is "builtins.dict[Any, Any]"
1159+
1160+ Ta6 = TypeAliasType("Ta6", Tuple[Unpack[Ts]]) # E: TypeVarTuple "Ts" is not included in type_params
1161+ unbound_tvt_alias: Ta6[int] # E: Bad number of arguments for type alias, expected 0, given 1
1162+ reveal_type(unbound_tvt_alias) # N: Revealed type is "builtins.tuple[Any, ...]"
1163+
1164+ class G(Generic[P, T]): ...
1165+ Ta7 = TypeAliasType("Ta7", G[P, T]) # E: ParamSpec "P" is not included in type_params \
1166+ # E: Type variable "T" is not included in type_params
1167+ unbound_ps_alias: Ta7[[int], str] # E: Bracketed expression "[...]" is not valid as a type \
1168+ # N: Did you mean "List[...]"? \
1169+ # E: Bad number of arguments for type alias, expected 0, given 2
1170+ reveal_type(unbound_ps_alias) # N: Revealed type is "__main__.G[Any, Any]"
1171+
1172+ # TODO this does not work yet, it should report unbound P
1173+ # Ta8 = TypeAliasType("Ta8", Callable[P, int])
1174+ # unbound_ps_alias: Ta8[int]
1175+ # reveal_type(unbound_ps_alias)
1176+
11511177
11521178[builtins fixtures/dict.pyi]
11531179
0 commit comments