mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-44353: Expand NewType tests for complex __qualname__. (#27311)
Make NewType pickleable by name.
This commit is contained in:
parent
4512848ab9
commit
e89ef0ad2a
2 changed files with 47 additions and 18 deletions
|
@ -2385,14 +2385,19 @@ class NewType:
|
|||
__call__ = _idfunc
|
||||
|
||||
def __init__(self, name, tp):
|
||||
self.__name__ = name
|
||||
self.__qualname__ = name
|
||||
if '.' in name:
|
||||
name = name.rpartition('.')[-1]
|
||||
self.__name__ = name
|
||||
self.__module__ = _callee(default='typing')
|
||||
self.__supertype__ = tp
|
||||
|
||||
def __repr__(self):
|
||||
return f'{self.__module__}.{self.__qualname__}'
|
||||
|
||||
def __reduce__(self):
|
||||
return self.__qualname__
|
||||
|
||||
def __or__(self, other):
|
||||
return Union[self, other]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue