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

Skip to content

Commit dc604a8

Browse files
sobolevnAlexWaygoodEclips4
authored
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>
1 parent a28e2ce commit dc604a8

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
@@ -2154,6 +2154,8 @@ class _AnnotatedAlias(_NotIterable, _GenericAlias, _root=True):
21542154
with extra annotations. The alias behaves like a normal typing alias,
21552155
instantiating is the same as instantiating the underlying type, binding
21562156
it to types is also the same.
2157+
2158+
The metadata itself is stored in a '__metadata__' attribute as a tuple.
21572159
"""
21582160
def __init__(self, origin, metadata):
21592161
if isinstance(origin, _AnnotatedAlias):
@@ -2209,6 +2211,10 @@ class Annotated:
22092211
Details:
22102212
22112213
- It's an error to call `Annotated` with less than two arguments.
2214+
- Access the metadata via the ``__metadata__`` attribute::
2215+
2216+
Annotated[int, '$'].__metadata__ == ('$',)
2217+
22122218
- Nested Annotated are flattened::
22132219
22142220
Annotated[Annotated[T, Ann1, Ann2], Ann3] == Annotated[T, Ann1, Ann2, Ann3]

0 commit comments

Comments
 (0)
0