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