@@ -72,6 +72,16 @@ def __call__(self, obj: Any, name: str, default: Any = ..., /) -> Any: ...
7272isclass = inspect .isclass
7373ismodule = inspect .ismodule
7474
75+ # Python 3.14 added the annotationlib module to the standard library as well as the
76+ # 'annotation_format' keyword parameter to inspect.signature(), which allows us to handle
77+ # forward references more robustly.
78+ if sys .version_info [0 :2 ] >= (3 , 14 ):
79+ import annotationlib # type: ignore[import-not-found]
80+
81+ inspect_signature_extra = {'annotation_format' : annotationlib .Format .FORWARDREF }
82+ else :
83+ inspect_signature_extra = {}
84+
7585
7686def unwrap (obj : Any ) -> Any :
7787 """Get an original object from wrapped object (wrapped functions).
@@ -718,12 +728,16 @@ def signature(
718728
719729 try :
720730 if _should_unwrap (subject ):
721- signature = inspect .signature (subject ) # type: ignore[arg-type]
731+ signature = inspect .signature (subject , ** inspect_signature_extra ) # type: ignore[arg-type]
722732 else :
723- signature = inspect .signature (subject , follow_wrapped = True ) # type: ignore[arg-type]
733+ signature = inspect .signature (
734+ subject , # type: ignore[arg-type]
735+ follow_wrapped = True ,
736+ ** inspect_signature_extra ,
737+ )
724738 except ValueError :
725739 # follow built-in wrappers up (ex. functools.lru_cache)
726- signature = inspect .signature (subject ) # type: ignore[arg-type]
740+ signature = inspect .signature (subject , ** inspect_signature_extra ) # type: ignore[arg-type]
727741 parameters = list (signature .parameters .values ())
728742 return_annotation = signature .return_annotation
729743
0 commit comments