]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-97797: Mention `__metadata__` in docstrings of `typing.{_AnnotatedAlias, Annotated...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 10 Apr 2023 15:21:45 +0000 (08:21 -0700)
committerGitHub <noreply@github.com>
Mon, 10 Apr 2023 15:21:45 +0000 (08:21 -0700)
(cherry picked from commit dc604a8c58af748ce25aee1af36b6521a3592fa5)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Kirill <80244920+Eclips4@users.noreply.github.com>
Lib/typing.py

index 8995564f89945d44cc06f50f1b02475a7b359672..7a50e06035376493682bb02920f7758f52f791dc 100644 (file)
@@ -2099,6 +2099,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):
@@ -2151,6 +2153,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]