Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
Closed
Labels
3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard 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
Description
Bug report
Bug description:
fromtypingimportSequencefromannotationlibimportFormat, get_annotationsclassA: x: fails[Sequence, undef] y: fails[list, undef] z: works[list, list] x_anno=get_annotations(A, format=Format.FORWARDREF)["x"] y_anno=get_annotations(A, format=Format.FORWARDREF)["y"] z_anno=get_annotations(A, format=Format.FORWARDREF)["z"] fails=dictworks=dictprint(x_anno.evaluate(format=Format.FORWARDREF)) print(y_anno.evaluate(format=Format.FORWARDREF)) print(z_anno.evaluate(format=Format.FORWARDREF))This should print:
dict[Sequence, undef] dict[list, undef] dict[list, list]Instead, the following is outputted:
ForwardRef('fails[__annotationlib_name_1__, undef]', is_class=True, owner=<class'__main__.A'>) ForwardRef('fails[__annotationlib_name_1__, undef]', is_class=True, owner=<class'__main__.A'>) dict[list, list]The issue seems to be that the globals are not considered when creating the _StringifierDict in this code path (whereas builtins and locals are):
https://github.com/python/cpython/blob/572df47840d910b9fc9cd951074232ae89442be1/Lib/annotationlib.py#L190C13-L196C14n
CPython versions tested on:
CPython main branch, 3.14
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard 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