Skip to content

Commit 4703e8d

Browse files
committed
Support functools.partial objects as annotate functions
1 parent a9a7f88 commit 4703e8d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Lib/annotationlib.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,11 @@ def _get_annotate_attr(annotate, attr, default):
896896
return getattr(call_func, attr, default)
897897
elif isinstance(annotate, type):
898898
return getattr(annotate.__init__, attr, default)
899+
elif (
900+
"functools" in sys.modules
901+
and isinstance(annotate, sys.modules["functools"].partial)
902+
):
903+
return getattr(annotate.func, attr, default)
899904

900905
return default
901906

@@ -912,6 +917,12 @@ def _direct_call_annotate(func, annotate, format):
912917
func(inst, format)
913918
return inst
914919

920+
if (
921+
"functools" in sys.modules
922+
and isinstance(annotate, sys.modules["functools"].partial)
923+
):
924+
return func(*annotate.args, format, **annotate.keywords)
925+
915926
return func(format)
916927

917928

0 commit comments

Comments
 (0)