[Python-checkins] GH-96079 Fix missing field name for _AnnotatedAlias (#96080)
gvanrossum
webhook-mailer at python.org
Wed Aug 31 19:02:33 EDT 2022
https://github.com/python/cpython/commit/0cd33e11fe6c77c423dbf3a7a9920daff012f006
commit: 0cd33e11fe6c77c423dbf3a7a9920daff012f006
branch: main
author: Anh71me <iyumelive at gmail.com>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2022-08-31T16:02:24-07:00
summary:
GH-96079 Fix missing field name for _AnnotatedAlias (#96080)
files:
A Misc/NEWS.d/next/Library/2022-08-31-11-10-21.gh-issue-96079.uqrXdJ.rst
M Lib/test/test_typing.py
M Lib/typing.py
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 9239673c248..015fa80942a 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -7143,6 +7143,7 @@ def test_special_attrs(self):
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 84fe007a9ee..95bd61c7f8c 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -2101,7 +2101,7 @@ def __init__(self, origin, metadata):
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 @@ def __getattr__(self, attr):
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 00000000000..4cb8d276cbe
--- /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.
More information about the Python-checkins
mailing list