summaryrefslogtreecommitdiffstats
path: root/Lib/copy_reg.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-09-28 18:13:29 (GMT)
committerGuido van Rossum <guido@python.org>2001-09-28 18:13:29 (GMT)
commit6cef6d5d62f083ada715da3610ce12147b625ee2 (patch)
treede5a51234c4e4675698d20abc03bd09c1b1ee0fc /Lib/copy_reg.py
parent19405a4a2a68570cae67501935adea3f375f84bf (diff)
downloadcpython-6cef6d5d62f083ada715da3610ce12147b625ee2.zip
cpython-6cef6d5d62f083ada715da3610ce12147b625ee2.tar.gz
cpython-6cef6d5d62f083ada715da3610ce12147b625ee2.tar.bz2
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.
Diffstat (limited to 'Lib/copy_reg.py')
-rw-r--r--Lib/copy_reg.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/copy_reg.py b/Lib/copy_reg.py
index eb02864..d469744 100644
--- a/Lib/copy_reg.py
+++ b/Lib/copy_reg.py
@@ -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