Changes to copy() and deepcopy() in copy.py to support __reduce__ as a

fallback for objects that are neither supported by our dispatch table
nor have a __copy__ or __deepcopy__ method.

Changes to _reduce() in copy_reg.py to support reducing objects that
don't have a __dict__ -- copy.copy(complex()) now invokes _reduce().

Add tests for copy.copy() and copy.deepcopy() to test_regrtest.py.
This commit is contained in:
Guido van Rossum 2001-09-28 18:13:29 +00:00
parent 19405a4a2a
commit 6cef6d5d62
3 changed files with 91 additions and 9 deletions

View file

@ -54,4 +54,12 @@ def _reduce(self):
state = None
else:
state = base(self)
return _reconstructor, (self.__class__, base, state), self.__dict__
args = (self.__class__, base, state)
try:
dict = self.__dict__
except AttributeError:
dict = None
if dict:
return _reconstructor, args, dict
else:
return _reconstructor, args