Skip to content

Commit 70decda

Browse files
committed
Fix generic ForwardRef evaluation with new locals
1 parent 95d6e0b commit 70decda

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Lib/annotationlib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ def evaluate(
167167
globals[param.__name__] = param
168168
if self.__extra_names__:
169169
locals = {**locals, **self.__extra_names__}
170+
if (annotate := getattr(owner, "__annotate__", None)) and annotate.__closure__:
171+
for name, cell in zip(annotate.__code__.co_freevars, annotate.__closure__):
172+
if name != "__classdict__":
173+
try:
174+
locals[name] = cell.cell_contents
175+
except ValueError:
176+
pass
170177

171178
arg = self.__forward_arg__
172179
if arg.isidentifier() and not keyword.iskeyword(arg):

0 commit comments

Comments
 (0)