Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

annotationlib:ref.evaluate(format=Format.FORWARDREF) not evaluating global generics with undefined params #138425

Closed
Labels
3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
@dr-carlos

Description

@dr-carlos

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

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp