Skip to content

Commit a35c683

Browse files
authored
gh-141489: Simplify closure/freevar iteration in annotationlib._build_closure() (#141490)
1 parent bc9b9d4 commit a35c683

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

Lib/annotationlib.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -844,14 +844,9 @@ def call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False):
844844
def _build_closure(annotate, owner, is_class, stringifier_dict, *, allow_evaluation):
845845
if not annotate.__closure__:
846846
return None, None
847-
freevars = annotate.__code__.co_freevars
848847
new_closure = []
849848
cell_dict = {}
850-
for i, cell in enumerate(annotate.__closure__):
851-
if i < len(freevars):
852-
name = freevars[i]
853-
else:
854-
name = "__cell__"
849+
for name, cell in zip(annotate.__code__.co_freevars, annotate.__closure__, strict=True):
855850
cell_dict[name] = cell
856851
new_cell = None
857852
if allow_evaluation:

0 commit comments

Comments
 (0)