Issue #28556: updates to typing.py (fix copy, deepcopy, pickle)

This commit is contained in:
Guido van Rossum 2016-10-29 12:44:29 -07:00
parent 5fc25a873c
commit b7dedc89f1
2 changed files with 27 additions and 0 deletions

View file

@ -190,6 +190,9 @@ class _FinalTypingBase(_TypingBase, _root=True):
return self
raise TypeError("Cannot instantiate %r" % cls)
def __reduce__(self):
return _trim_name(type(self).__name__)
class _ForwardRef(_TypingBase, _root=True):
"""Wrapper to hold a forward reference."""
@ -1051,6 +1054,11 @@ class GenericMeta(TypingMeta, abc.ABCMeta):
# classes are supposed to be rare anyways.
return issubclass(instance.__class__, self)
def __copy__(self):
return self.__class__(self.__name__, self.__bases__, dict(self.__dict__),
self.__parameters__, self.__args__, self.__origin__,
self.__extra__, self.__orig_bases__)
# Prevent checks for Generic to crash when defining Generic.
Generic = None