gh-141489: Simplify closure/freevar iteration in annotationlib._build_closure() (#141490)

This commit is contained in:
dr-carlos 2025-11-20 14:38:08 +10:30 committed by GitHub
parent bc9b9d47f9
commit a35c683da5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -844,14 +844,9 @@ def call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False):
def _build_closure(annotate, owner, is_class, stringifier_dict, *, allow_evaluation):
if not annotate.__closure__:
return None, None
freevars = annotate.__code__.co_freevars
new_closure = []
cell_dict = {}
for i, cell in enumerate(annotate.__closure__):
if i < len(freevars):
name = freevars[i]
else:
name = "__cell__"
for name, cell in zip(annotate.__code__.co_freevars, annotate.__closure__, strict=True):
cell_dict[name] = cell
new_cell = None
if allow_evaluation: