[issue45380] help() appears confused about the module of typing.Annotated
Alex Waygood
report at bugs.python.org
Sun Oct 10 12:40:20 EDT 2021
Alex Waygood <Alex.Waygood at Gmail.com> added the comment:
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.
----------
versions: +Python 3.11
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45380>
_______________________________________
More information about the Python-bugs-list
mailing list