GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — annotationlib.get_annotations() infinite loop on __wrapped__ cycle (eval_str=True) · Issue #146556 · python/cpython Closed Closed Copy link Labels stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportBug description:
Reproducerimport annotationlib def f(x: 'int') -> 'str': pass f.__wrapped__ = f # self-referential cycle # Hangs forever, never returns annotationlib.get_annotations(f, eval_str=True) Two-node cycle also triggers it: def g(): pass f.__wrapped__ = g g.__wrapped__ = f annotationlib.get_annotations(f, eval_str=True) # hangs Root CauseIn if not eval_str: return dict(ann) # fast path, skips unwrap entirely for default eval_str=False When if unwrap is not None: while True: if hasattr(unwrap, "__wrapped__"): unwrap = unwrap.__wrapped__ # no cycle detection continue if functools := sys.modules.get("functools"): if isinstance(unwrap, functools.partial): unwrap = unwrap.func # also no cycle detection continue break FixApply the same cycle-detection pattern used by if unwrap is not None: seen = {id(unwrap)} while True: if hasattr(unwrap, "__wrapped__"): candidate = unwrap.__wrapped__ if id(candidate) in seen: break seen.add(id(candidate)) unwrap = candidate continue if functools := sys.modules.get("functools"): if isinstance(unwrap, functools.partial): candidate = unwrap.func if id(candidate) in seen: break seen.add(id(candidate)) unwrap = candidate continue break if hasattr(unwrap, "__globals__"): obj_globals = unwrap.__globals__ CPython versions tested on:CPython main branch Operating systems tested on:Linux Linked PRsActivity
MetadataMetadataAssigneesLabelsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |