Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dc604a8

Browse filesBrowse files
sobolevnAlexWaygoodEclips4
authored
pythongh-97797: Mention __metadata__ in docstrings of typing.{_AnnotatedAlias, Annotated} (python#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
Copy full SHA for dc604a8

File tree

1 file changed

+6
-0
lines changed
Filter options

1 file changed

+6
-0
lines changed

‎Lib/typing.py

Copy file name to clipboardExpand all lines: Lib/typing.py
+6Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.