- Patch 1433928:
- The copy module now "copies" function objects (as atomic objects).
- dict.__getitem__ now looks for a __missing__ hook before raising
KeyError.
- Added a new type, defaultdict, to the collections module.
This uses the new __missing__ hook behavior added to dict (see above).
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index bd5a3e1..ff4c987 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -568,6 +568,22 @@
raise ValueError, "ain't got no stickin' state"
self.assertRaises(ValueError, copy.copy, EvilState())
+ def test_copy_function(self):
+ self.assertEqual(copy.copy(global_foo), global_foo)
+ def foo(x, y): return x+y
+ self.assertEqual(copy.copy(foo), foo)
+ bar = lambda: None
+ self.assertEqual(copy.copy(bar), bar)
+
+ def test_deepcopy_function(self):
+ self.assertEqual(copy.deepcopy(global_foo), global_foo)
+ def foo(x, y): return x+y
+ self.assertEqual(copy.deepcopy(foo), foo)
+ bar = lambda: None
+ self.assertEqual(copy.deepcopy(bar), bar)
+
+def global_foo(x, y): return x+y
+
def test_main():
test_support.run_unittest(TestCopy)