4444
4545
4646if not TYPE_CHECKING :
47- if sys .version_info >= (3 , 11 ):
47+ if sys .version_info >= (3 , 13 ):
48+ from typing import _collect_type_parameters as _collect_parameters
49+ elif sys .version_info >= (3 , 11 ):
4850 from typing import _collect_parameters
4951 else :
5052 from typing import _collect_type_vars as _collect_parameters
@@ -809,13 +811,17 @@ class A(Base):
809811 if value is None : # type: ignore[no-any-expr]
810812 value = type (None )
811813 if isinstance (value , str ): # type: ignore[no-any-expr]
812- if sys .version_info < (3 , 9 ):
813- value = ForwardRef (value , is_argument = False )
814- else :
815- value = ForwardRef (value , is_argument = False , is_class = True )
816- value = typing ._eval_type (value , base_globals , base_locals , recursive_guard = 1 ) # type: ignore[attr-defined, no-any-expr]
814+ value = ForwardRef (value , is_argument = False , is_class = True )
815+ if sys .version_info < (3 , 12 ):
816+ value = typing ._eval_type (value , base_globals , base_locals ) # type: ignore[attr-defined, no-any-expr]
817+ else :
818+ value = typing ._eval_type ( # type: ignore[attr-defined]
819+ value , # type: ignore[no-any-expr]
820+ base_globals , # type: ignore[no-any-expr]
821+ base_locals , # type: ignore[no-any-expr]
822+ base .__type_params__ ,
823+ )
817824 hints [name ] = value # type: ignore[no-any-expr]
818-
819825 return hints if include_extras else {k : _strip_annotations (t ) for k , t in hints .items ()} # type: ignore[no-any-expr]
820826
821827 if globalns is None :
@@ -836,8 +842,9 @@ class A(Base):
836842 # Return empty annotations for something that _could_ have them.
837843 if isinstance (obj , typing ._allowed_types ): # type: ignore[ unreachable]
838844 return {}
839- raise TypeError (f"{ obj !r} is not a module, class, method, " " or function." )
845+ raise TypeError (f"{ obj !r} is not a module, class, method, or function." )
840846 hints = dict (hints ) # type: ignore[no-any-expr]
847+ type_params = getattr (obj , "__type_params__" , ()) # type: ignore[no-any-expr]
841848 for name , value in hints .items (): # type: ignore[no-any-expr]
842849 if value is None : # type: ignore[no-any-expr]
843850 value = type (None )
@@ -849,5 +856,8 @@ class A(Base):
849856 is_argument = not isinstance (cast (object , obj ), types .ModuleType ),
850857 is_class = False ,
851858 )
852- hints [name ] = typing ._eval_type (value , globalns , localns ) # type: ignore[no-any-expr, attr-defined]
859+ if sys .version_info >= (3 , 12 ):
860+ hints [name ] = typing ._eval_type (value , globalns , localns , type_params = type_params ) # type: ignore[no-any-expr, attr-defined]
861+ else :
862+ hints [name ] = typing ._eval_type (value , globalns , localns ) # type: ignore[no-any-expr, attr-defined]
853863 return hints if include_extras else {k : _strip_annotations (t ) for k , t in hints .items ()} # type: ignore[no-any-expr]
0 commit comments