Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4568,6 +4568,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 Expand Up @@ -4908,7 +4913,8 @@ def test_special_attrs(self):
typing.TypeVar: 'TypeVar',
typing.Union: 'Union',
# Subscribed special forms
typing.Annotated[Any, "Annotation"]: 'Annotated',
# Fixme: make Annotated work without messing up its MRO
# typing.Annotated[Any, "Annotation"]: 'Annotated',
typing.ClassVar[Any]: 'ClassVar',
typing.Concatenate[Any, SpecialAttrsP]: 'Concatenate',
typing.Final[Any]: 'Final',
Expand Down
2 changes: 1 addition & 1 deletion Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,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)
Comment thread
Fidget-Spinner marked this conversation as resolved.
self.__metadata__ = metadata

def copy_with(self, params):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Temporarily remove ``__name__`` and ``__qualname__`` from subscripted
:data:`typing.Annotated` to maintain MRO.