]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-141489: Simplify closure/freevar iteration in `annotationlib._build_closure...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 20 Nov 2025 04:33:18 +0000 (05:33 +0100)
committerGitHub <noreply@github.com>
Thu, 20 Nov 2025 04:33:18 +0000 (04:33 +0000)
gh-141489: Simplify closure/freevar iteration in `annotationlib._build_closure()` (GH-141490)
(cherry picked from commit a35c683da55e77c96828fd0421640787337cfc64)

Co-authored-by: dr-carlos <77367421+dr-carlos@users.noreply.github.com>
Lib/annotationlib.py

index 33907b1fc2a53a5c2bb8337b3710219eb36acc28..a5788cdbfae3f5f7a0c0962605108796468362fc 100644 (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: