This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author AlexWaygood
Recipients AlexWaygood, docs@python
Date 2021-10-10.16:40:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1633884020.65.0.925212925133.issue45380@roundup.psfhosted.org>
In-reply-to
Content
It actually appears as though there is no documented way to retrieve the metadata from an annotated alias. Is this intentional?

The metadata is stored in a `__metadata__` attribute of a `typing._AnnotatedAlias` instance. But the `__metadata__` attribute is undocumented -- there is no mention of it in the docstring for `_AnnotatedAlias`, in the documentation for `typing.Annotated` (https://docs.python.org/3.11/library/typing.html#typing.Annotated), or PEP 593, which introduced `typing.Annotated` (https://www.python.org/dev/peps/pep-0593/).

The documentation says: "Passing include_extras=True to get_type_hints() lets one access the extra annotations at runtime." However, this is misleading. Calling `get_type_hints` on a function/class where an argument/attribute is annotated with an `_AnnotatedAlias` instance is a way of retrieving the type hints for the function/class with the `_AnnotatedAlias` instance unresolved. However, if you call `get_type_hints` on the `_AnnotatedAlias` instance directly, this fails.
History
Date User Action Args
2021-10-10 16:40:20AlexWaygoodsetrecipients: + AlexWaygood, docs@python
2021-10-10 16:40:20AlexWaygoodsetmessageid: <1633884020.65.0.925212925133.issue45380@roundup.psfhosted.org>
2021-10-10 16:40:20AlexWaygoodlinkissue45380 messages
2021-10-10 16:40:20AlexWaygoodcreate