Skip to content

Commit ae68a42

Browse files
committed
use forwardref instead
1 parent d64ded3 commit ae68a42

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Lib/unittest/mock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _get_signature_object(func, as_instance, eat_self):
120120
else:
121121
sig_func = func
122122
try:
123-
return func, inspect.signature(sig_func, annotation_format=Format.STRING)
123+
return func, inspect.signature(sig_func, annotation_format=Format.FORWARDREF)
124124
except ValueError:
125125
# Certain callable types are not supported by inspect.signature()
126126
return None
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Request signature during mock autospec with string annotation format
1+
Request signature during mock autospec with forwardref annotation format.
2+
This prevents runtime errors when a type referred in a type hint is
3+
imported within a `TYPE_CHECKING` block.

0 commit comments

Comments
 (0)