mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
bpo-44524: Don't modify MRO when inheriting from typing.Annotated (GH-27841)
(cherry picked from commit 23384a1749
)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
This commit is contained in:
parent
ec5a03168f
commit
06e9a35169
2 changed files with 11 additions and 1 deletions
|
@ -1573,7 +1573,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):
|
||||
|
@ -1601,6 +1601,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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue