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 90916c4

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

File tree

Expand file treeCollapse file tree

1 file changed

+6
-0
lines changed
Filter options
Expand file treeCollapse file tree

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
@@ -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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.