diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-04-10 14:57:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 14:57:17 (GMT) |
commit | dc604a8c58af748ce25aee1af36b6521a3592fa5 (patch) | |
tree | dd70e107a6a0b7a70bc46a509f15e44b7e89e546 | |
parent | a28e2ce3fbcc852959324879e0bbf5ba8ecf0105 (diff) | |
download | cpython-dc604a8c58af748ce25aee1af36b6521a3592fa5.zip cpython-dc604a8c58af748ce25aee1af36b6521a3592fa5.tar.gz cpython-dc604a8c58af748ce25aee1af36b6521a3592fa5.tar.bz2 |
gh-97797: Mention `__metadata__` in docstrings of `typing.{_AnnotatedAlias, Annotated}` (#103405)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Kirill <80244920+Eclips4@users.noreply.github.com>
-rw-r--r-- | Lib/typing.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 1f1c4ff..7c16556 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -2154,6 +2154,8 @@ class _AnnotatedAlias(_NotIterable, _GenericAlias, _root=True): with extra annotations. The alias behaves like a normal typing alias, instantiating is the same as instantiating the underlying type, binding it to types is also the same. + + The metadata itself is stored in a '__metadata__' attribute as a tuple. """ def __init__(self, origin, metadata): if isinstance(origin, _AnnotatedAlias): @@ -2209,6 +2211,10 @@ class Annotated: Details: - It's an error to call `Annotated` with less than two arguments. + - Access the metadata via the ``__metadata__`` attribute:: + + Annotated[int, '$'].__metadata__ == ('$',) + - Nested Annotated are flattened:: Annotated[Annotated[T, Ann1, Ann2], Ann3] == Annotated[T, Ann1, Ann2, Ann3] |