8000 gh-97797: Mention `__metadata__` in docstrings of `typing.{_Annotated… · python/cpython@0f6319f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f6319f

Browse files
miss-islingtonsobolevnAlexWaygoodEclips4
authored
gh-97797: Mention __metadata__ in docstrings of typing.{_AnnotatedAlias, Annotated} (GH-103405)
(cherry picked from commit dc604a8) 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>
1 parent 4e284ff commit 0f6319f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Lib/typing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,8 @@ class _AnnotatedAlias(_NotIterable, _GenericAlias, _root=True):
20992099
with extra annotations. The alias behaves like a normal typing alias,
21002100
instantiating is the same as instantiating the underlying type, binding
21012101
it to types is also the same.
2102+
2103+
The metadata itself is stored in a '__metadata__' attribute as a tuple.
21022104
"""
21032105
def __init__(self, origin, metadata):
21042106
if isinstance(origin, _AnnotatedAlias):
@@ -2151,6 +2153,10 @@ class Annotated:
21512153
Details:
21522154
21532155
- It's an error to call `Annotated` with less than two arguments.
2156+
- Access the metadata via the ``__metadata__`` attribute::
2157+
2158+
Annotated[int, '$'].__metadata__ == ('$',)
2159+
21542160
- Nested Annotated are flattened::
21552161
21562162
Annotated[Annotated[T, Ann1, Ann2], Ann3] == Annotated[T, Ann1, Ann2, Ann3]

0 commit comments

Comments
 (0)
0