Skip to content

Commit e177621

Browse files
committed
Improve backup paths for annotate functions without __builtins__
1 parent 1ab0139 commit e177621

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Lib/annotationlib.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,12 @@ def call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False):
781781
# want to return objects with more user-friendly behavior, such as an __eq__
782782
# that returns a bool and an defined set of attributes.
783783
annotate_globals = getattr(annotate, "__globals__", {})
784-
namespace = {**getattr(annotate, "__builtins__", builtins.__dict__), **annotate_globals}
784+
if annotate_builtins := getattr(annotate, "__builtins__", None):
785+
namespace = {**annotate_builtins, **annotate_globals}
786+
elif annotate_builtins := annotate_globals.get("__builtins__"):
787+
namespace = {**annotate_builtins, **annotate_globals}
788+
else:
789+
namespace = {**builtins.__dict__, **annotate_globals}
785790
is_class = isinstance(owner, type)
786791
globals = _StringifierDict(
787792
namespace,

0 commit comments

Comments
 (0)