summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-07-24 07:40:08 (GMT)
committerGitHub <noreply@github.com>2021-07-24 07:40:08 (GMT)
commite89ef0ad2a299770a88ece8f7a316f7d3eb65c9f (patch)
treeb7c4eaaf517e1b684aae77c81b406d0045513fe1 /Lib/typing.py
parent4512848ab92c8ed6aafb54d6e1908b1074558c43 (diff)
downloadcpython-e89ef0ad2a299770a88ece8f7a316f7d3eb65c9f.zip
cpython-e89ef0ad2a299770a88ece8f7a316f7d3eb65c9f.tar.gz
cpython-e89ef0ad2a299770a88ece8f7a316f7d3eb65c9f.tar.bz2
bpo-44353: Expand NewType tests for complex __qualname__. (#27311)
Make NewType pickleable by name.
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index e618513..198837c 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -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]