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: `ref.evaluate()` not working for generics as local variables · Issue #138151 · python/cpython Closed Labels stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportBug description:Usually, when a local variable is introduced after getting a ForwardRef, evaluate() picks this up and correctly evaluates it using the from annotationlib import Format, get_annotations def works_global(): class Demo: x: sequence_a[int] fwdref = get_annotations(Demo, format=Format.FORWARDREF)['x'] print(f"Global {fwdref!r}") global sequence_a sequence_a = list evaluated = fwdref.evaluate() print(f"Evaluated {evaluated!r}") def works_nongeneric(): class Demo: nonlocal alias # Optional x: alias fwdref = get_annotations(Demo, format=Format.FORWARDREF)['x'] print(f"Global {fwdref!r}") alias = int evaluated = fwdref.evaluate() print(f"Evaluated {evaluated!r}") def fails(): class Demo: nonlocal sequence_b x: sequence_b[int] fwdref = get_annotations(Demo, format=Format.FORWARDREF)['x'] print(f"Local {fwdref!r}") sequence_b = list evaluated = fwdref.evaluate() # NameError print(f"Evaluated {evaluated!r}") works_global() works_nongeneric() fails() CPython versions tested on:CPython main branch, 3.14 Operating systems tested on:Linux Linked PRsActivity
MetadataMetadataAssigneesLabelsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-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. |