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

typing.get_type_hints Can Return Incorrect Type for Annotated Metadata #112618

Closed
Labels
3.11only security fixes3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
@cmg2146

Description

@cmg2146

Bug report

Bug description:

When running the following example:

fromtypingimportAnnotated,get_type_hintsclassMessageCode(str):passclassDisplayName(str):passclassMessage:field_a:Annotated[str,MessageCode("A")]classForm:box_a:Annotated[str,DisplayName("A")]hints=get_type_hints(Message,include_extras=True)metadata=hints["field_a"].__metadata__[0]print(f"MessageCode metadata type:{type(metadata)}")hints=get_type_hints(Form,include_extras=True)metadata=hints["box_a"].__metadata__[0]print(f"DisplayName metadata type:{type(metadata)}")

the output will be:

MessageCode metadata type: <class '__main__.MessageCode'>DisplayName metadata type: <class '__main__.MessageCode'>

when it should be:

MessageCode metadata type: <class '__main__.MessageCode'>DisplayName metadata type: <class '__main__.DisplayName'>

This issue seems to occur only when:

  • the metadata subclasses an immutable type
  • when multiple instances of such metadata appear in different class definitions and they have the same value

CPython versions tested on:

3.9

Operating systems tested on:

Linux, Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs 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