@@ -4682,7 +4682,7 @@ def visit_type_application(self, tapp: TypeApplication) -> Type:
46824682 """
46834683 if isinstance (tapp .expr , RefExpr ) and isinstance (tapp .expr .node , TypeAlias ):
46844684 if tapp .expr .node .python_3_12_type_alias :
4685- return self .named_type ( "typing.TypeAliasType" )
4685+ return self .type_alias_type_type ( )
46864686 # Subscription of a (generic) alias in runtime context, expand the alias.
46874687 item = instantiate_type_alias (
46884688 tapp .expr .node ,
@@ -4746,7 +4746,7 @@ class LongName(Generic[T]): ...
47464746 y = cast(A, ...)
47474747 """
47484748 if alias .python_3_12_type_alias :
4749- return self .named_type ( "typing.TypeAliasType" )
4749+ return self .type_alias_type_type ( )
47504750 if isinstance (alias .target , Instance ) and alias .target .invalid : # type: ignore[misc]
47514751 # An invalid alias, error already has been reported
47524752 return AnyType (TypeOfAny .from_error )
@@ -5862,6 +5862,12 @@ def named_type(self, name: str) -> Instance:
58625862 """
58635863 return self .chk .named_type (name )
58645864
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+
58655871 def is_valid_var_arg (self , typ : Type ) -> bool :
58665872 """Is a type valid as a *args argument?"""
58675873 typ = get_proper_type (typ )
0 commit comments