@@ -4679,7 +4679,7 @@ def visit_type_application(self, tapp: TypeApplication) -> Type:
46794679 """
46804680 if isinstance (tapp .expr , RefExpr ) and isinstance (tapp .expr .node , TypeAlias ):
46814681 if tapp .expr .node .python_3_12_type_alias :
4682- return self .named_type ( "typing.TypeAliasType" )
4682+ return self .type_alias_type_type ( )
46834683 # Subscription of a (generic) alias in runtime context, expand the alias.
46844684 item = instantiate_type_alias (
46854685 tapp .expr .node ,
@@ -4743,7 +4743,7 @@ class LongName(Generic[T]): ...
47434743 y = cast(A, ...)
47444744 """
47454745 if alias .python_3_12_type_alias :
4746- return self .named_type ( "typing.TypeAliasType" )
4746+ return self .type_alias_type_type ( )
47474747 if isinstance (alias .target , Instance ) and alias .target .invalid : # type: ignore[misc]
47484748 # An invalid alias, error already has been reported
47494749 return AnyType (TypeOfAny .from_error )
@@ -5863,6 +5863,12 @@ def named_type(self, name: str) -> Instance:
58635863 """
58645864 return self .chk .named_type (name )
58655865
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+
58665872 def is_valid_var_arg (self , typ : Type ) -> bool :
58675873 """Is a type valid as a *args argument?"""
58685874 typ = get_proper_type (typ )
0 commit comments