8000 bpo-44524: Don't modify MRO when inheriting from typing.Annotated by Fidget-Spinner · Pull Request #27841 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44524: Don't modify MRO when inheriting from typing.Annotated #27841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
F 10000 ailed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
exclude Annotated from _name temporarily
  • Loading branch information
Fidget-Spinner committed Aug 19, 2021
commit ce1923882982cb3296dc2a6cb54235e6355d1337
7 changes: 6 additions & 1 deletion Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4568,6 +4568,10 @@ 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.assertNotIn(Generic, X.__mro__, "Annotated should be transparent.")


class TypeAliasTests(BaseTestCase):
def test_canonical_usage_with_variable_annotation(self):
Expand Down Expand Up @@ -4908,7 +4912,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)
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.
0