From 0cd33e11fe6c77c423dbf3a7a9920daff012f006 Mon Sep 17 00:00:00 2001 From: Anh71me Date: Thu, 1 Sep 2022 07:02:24 +0800 Subject: GH-96079 Fix missing field name for _AnnotatedAlias (#96080) --- Lib/test/test_typing.py | 1 + Lib/typing.py | 5 ++++- .../next/Library/2022-08-31-11-10-21.gh-issue-96079.uqrXdJ.rst | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2022-08-31-11-10-21.gh-issue-96079.uqrXdJ.rst diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 9239673..015fa80 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -7143,6 +7143,7 @@ class SpecialAttrsTests(BaseTestCase): typing.Self: 'Self', # Subscribed special forms typing.Annotated[Any, "Annotation"]: 'Annotated', + typing.Annotated[int, 'Annotation']: 'Annotated', typing.ClassVar[Any]: 'ClassVar', typing.Concatenate[Any, SpecialAttrsP]: 'Concatenate', typing.Final[Any]: 'Final', diff --git a/Lib/typing.py b/Lib/typing.py index 84fe007..95bd61c 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -2101,7 +2101,7 @@ class _AnnotatedAlias(_NotIterable, _GenericAlias, _root=True): if isinstance(origin, _AnnotatedAlias): metadata = origin.__metadata__ + metadata origin = origin.__origin__ - super().__init__(origin, origin) + super().__init__(origin, origin, name='Annotated') self.__metadata__ = metadata def copy_with(self, params): @@ -2134,6 +2134,9 @@ class _AnnotatedAlias(_NotIterable, _GenericAlias, _root=True): return 'Annotated' return super().__getattr__(attr) + def __mro_entries__(self, bases): + return (self.__origin__,) + class Annotated: """Add context specific metadata to a type. diff --git a/Misc/NEWS.d/next/Library/2022-08-31-11-10-21.gh-issue-96079.uqrXdJ.rst b/Misc/NEWS.d/next/Library/2022-08-31-11-10-21.gh-issue-96079.uqrXdJ.rst new file mode 100644 index 0000000..4cb8d27 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-08-31-11-10-21.gh-issue-96079.uqrXdJ.rst @@ -0,0 +1 @@ +In :mod:`typing`, fix missing field ``name`` and incorrect ``__module__`` in _AnnotatedAlias. -- cgit v0.12