Add support for copy_reg.dispatch_table.
Rewrote copy() and deepcopy() without avoidable try/except statements;
getattr(x, name, None) or dict.get() are much faster than try/except.
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index c97d54d..35ce46a 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -2,6 +2,7 @@
import sys
import copy
+import copy_reg
import unittest
from test import test_support
@@ -32,6 +33,19 @@
self.assertEqual(y.__class__, x.__class__)
self.assertEqual(y.foo, x.foo)
+ def test_copy_registry(self):
+ class C(object):
+ def __new__(cls, foo):
+ obj = object.__new__(cls)
+ obj.foo = foo
+ return obj
+ def pickle_C(obj):
+ return (C, (obj.foo,))
+ x = C(42)
+ self.assertRaises(TypeError, copy.copy, x)
+ copy_reg.pickle(C, pickle_C, C)
+ y = copy.copy(x)
+
def test_copy_reduce(self):
class C(object):
def __reduce__(self):
@@ -182,6 +196,19 @@
self.assertEqual(y.__class__, x.__class__)
self.assertEqual(y.foo, x.foo)
+ def test_deepcopy_registry(self):
+ class C(object):
+ def __new__(cls, foo):
+ obj = object.__new__(cls)
+ obj.foo = foo
+ return obj
+ def pickle_C(obj):
+ return (C, (obj.foo,))
+ x = C(42)
+ self.assertRaises(TypeError, copy.deepcopy, x)
+ copy_reg.pickle(C, pickle_C, C)
+ y = copy.deepcopy(x)
+
def test_deepcopy_reduce(self):
class C(object):
def __reduce__(self):