-
- Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13bugs and security fixesbugs 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:
When running the following example:
from typing import Annotated, get_type_hints class MessageCode(str): pass class DisplayName(str): pass class Message: field_a: Annotated[str, MessageCode("A")] class Form: 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
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13bugs and security fixesbugs 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