Skip to content

Commit d98ef64

Browse files
committed
Implement non-func callable annotate support for call_annotate_function(format=Format.STRING)
1 parent 0328ac1 commit d98ef64

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Lib/annotationlib.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,18 @@ def call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False):
728728
annotate, owner, is_class, globals, allow_evaluation=False
729729
)
730730
func = types.FunctionType(
731-
annotate.__code__,
731+
_get_annotate_attr(annotate, "__code__", None),
732732
globals,
733733
closure=closure,
734-
argdefs=annotate.__defaults__,
735-
kwdefaults=annotate.__kwdefaults__,
734+
argdefs=_get_annotate_attr(annotate, "__defaults__", None),
735+
kwdefaults=_get_annotate_attr(annotate, "__kwdefaults__", None),
736736
)
737-
annos = func(Format.VALUE_WITH_FAKE_GLOBALS)
737+
if isinstance(annotate.__call__, types.MethodType):
738+
annos = func(
739+
annotate.__call__.__self__, Format.VALUE_WITH_FAKE_GLOBALS
740+
)
741+
else:
742+
annos = func(Format.VALUE_WITH_FAKE_GLOBALS)
738743
if _is_evaluate:
739744
return _stringify_single(annos)
740745
return {

0 commit comments

Comments
 (0)