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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 5 Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4512,6 +4512,11 @@ def test_annotated_in_other_types(self):
X = List[Annotated[T, 5]]
self.assertEqual(X[int], List[Annotated[int, 5]])

def test_annotated_mro(self):
class X(Annotated[int, (1, 10)]): ...
self.assertEqual(X.__mro__, (X, int, object),
"Annotated should be transparent.")


class TypeAliasTests(BaseTestCase):
def test_canonical_usage_with_variable_annotation(self):
Expand Down
7 changes: 6 additions & 1 deletion 7 Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ def __init__(self, origin, metadata):
if isinstance(origin, _AnnotatedAlias):
metadata = origin.__metadata__ + metadata
origin = origin.__origin__
super().__init__(origin, origin, name="Annotated")
super().__init__(origin, origin)
self.__metadata__ = metadata

def copy_with(self, params):
Expand Down Expand Up @@ -1601,6 +1601,11 @@ def __eq__(self, other):
def __hash__(self):
return hash((self.__origin__, self.__metadata__))

def __getattr__(self, attr):
if attr in {'__name__', '__qualname__'}:
return 'Annotated'
return super().__getattr__(attr)


class Annotated:
"""Add context specific metadata to a type.
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.