@@ -4682,7 +4682,7 @@ def visit_type_application(self, tapp: TypeApplication) -> Type:
4682
4682
"""
4683
4683
if isinstance (tapp .expr , RefExpr ) and isinstance (tapp .expr .node , TypeAlias ):
4684
4684
if tapp .expr .node .python_3_12_type_alias :
4685
- return self .named_type ( "typing.TypeAliasType" )
4685
+ return self .type_alias_type_type ( )
4686
4686
# Subscription of a (generic) alias in runtime context, expand the alias.
4687
4687
item = instantiate_type_alias (
4688
4688
tapp .expr .node ,
@@ -4746,7 +4746,7 @@ class LongName(Generic[T]): ...
4746
4746
y = cast(A, ...)
4747
4747
"""
4748
4748
if alias .python_3_12_type_alias :
4749
- return self .named_type ( "typing.TypeAliasType" )
4749
+ return self .type_alias_type_type ( )
4750
4750
if isinstance (alias .target , Instance ) and alias .target .invalid : # type: ignore[misc]
4751
4751
# An invalid alias, error already has been reported
4752
4752
return AnyType (TypeOfAny .from_error )
@@ -5862,6 +5862,12 @@ def named_type(self, name: str) -> Instance:
5862
5862
"""
5863
5863
return self .chk .named_type (name )
5864
5864
5865
+ def type_alias_type_type (self ) -> Instance :
5866
+ """Returns a `typing.TypeAliasType` or `typing_extensions.TypeAliasType`."""
5867
+ if self .chk .options .python_version >= (3 , 12 ):
5868
+ return self .named_type ("typing.TypeAliasType" )
5869
+ return self .named_type ("typing_extensions.TypeAliasType" )
5870
+
5865
5871
def is_valid_var_arg (self , typ : Type ) -> bool :
5866
5872
"""Is a type valid as a *args argument?"""
5867
5873
typ = get_proper_type (typ )
0 commit comments