mirror of
https://github.com/python/cpython.git
synced 2025-11-24 12:20:42 +00:00
[3.14] gh-141489: Simplify closure/freevar iteration in annotationlib._build_closure() (GH-141490) (#141776)
gh-141489: Simplify closure/freevar iteration in `annotationlib._build_closure()` (GH-141490)
(cherry picked from commit a35c683da5)
Co-authored-by: dr-carlos <77367421+dr-carlos@users.noreply.github.com>
This commit is contained in:
parent
072eeaf84c
commit
83cfd87568
1 changed files with 1 additions and 6 deletions
|
|
@ -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):
|
def _build_closure(annotate, owner, is_class, stringifier_dict, *, allow_evaluation):
|
||||||
if not annotate.__closure__:
|
if not annotate.__closure__:
|
||||||
return None, None
|
return None, None
|
||||||
freevars = annotate.__code__.co_freevars
|
|
||||||
new_closure = []
|
new_closure = []
|
||||||
cell_dict = {}
|
cell_dict = {}
|
||||||
for i, cell in enumerate(annotate.__closure__):
|
for name, cell in zip(annotate.__code__.co_freevars, annotate.__closure__, strict=True):
|
||||||
if i < len(freevars):
|
|
||||||
name = freevars[i]
|
|
||||||
else:
|
|
||||||
name = "__cell__"
|
|
||||||
cell_dict[name] = cell
|
cell_dict[name] = cell
|
||||||
new_cell = None
|
new_cell = None
|
||||||
if allow_evaluation:
|
if allow_evaluation:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue