Skip to content

Commit a2d9aa0

Browse files
dr-carlosashm-dev
authored andcommitted
pythongh-141489: Simplify closure/freevar iteration in annotationlib._build_closure() (python#141490)
1 parent 28f3cc0 commit a2d9aa0

1 file changed

Lines changed: 1 addition & 6 deletions

File tree

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)