diff options
author | Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> | 2021-08-25 18:13:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-25 18:13:59 (GMT) |
commit | 23384a1749359f0ae7aaae052073d44b59e715a1 (patch) | |
tree | 173d8393cd1f565c4a60fff1e6c6b83bdab8d984 /Lib/typing.py | |
parent | 551da597a0996b0fb3af425f48aa5bc63ea6b963 (diff) | |
download | cpython-23384a1749359f0ae7aaae052073d44b59e715a1.zip cpython-23384a1749359f0ae7aaae052073d44b59e715a1.tar.gz cpython-23384a1749359f0ae7aaae052073d44b59e715a1.tar.bz2 |
bpo-44524: Don't modify MRO when inheriting from typing.Annotated (GH-27841)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index a283fe4..35c57c2 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1575,7 +1575,7 @@ class _AnnotatedAlias(_GenericAlias, _root=True): 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): @@ -1603,6 +1603,11 @@ class _AnnotatedAlias(_GenericAlias, _root=True): 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. |