Skip to content

Commit c19bcbd

Browse files
committed
Fail if NotImplementedError is raised for VALUE_WITH_FAKE_GLOBALS
1 parent 8296cd8 commit c19bcbd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Lib/annotationlib.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,17 @@ def call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False):
664664
# possibly constants if the annotate function uses them directly). We then
665665
# convert each of those into a string to get an approximation of the
666666
# original source.
667+
668+
# Attempt to call with VALUE_WITH_FAKE_GLOBALS to check if it is implemented
669+
# See: https://github.com/python/cpython/issues/138764
670+
# Only fail on NotImplementedError
671+
try:
672+
annotate(Format.VALUE_WITH_FAKE_GLOBALS)
673+
except NotImplementedError:
674+
raise
675+
except Exception:
676+
pass
677+
667678
globals = _StringifierDict({}, format=format)
668679
is_class = isinstance(owner, type)
669680
closure = _build_closure(
@@ -722,6 +733,10 @@ def call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False):
722733
)
723734
try:
724735
result = func(Format.VALUE_WITH_FAKE_GLOBALS)
736+
except NotImplementedError:
737+
# If NotImplementedError is raised, don't try to call again with
738+
# no globals.
739+
raise
725740
except Exception:
726741
pass
727742
else:

0 commit comments

Comments
 (0)