]> granicus.if.org Git - python/commitdiff
Merged revisions 76571 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 28 Nov 2009 15:58:27 +0000 (15:58 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 28 Nov 2009 15:58:27 +0000 (15:58 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r76571 | antoine.pitrou | 2009-11-28 16:55:58 +0100 (sam., 28 nov. 2009) | 3 lines

  Issue #1515: Enable use of deepcopy() with instance methods.  Patch by Robert Collins.
........

Lib/copy.py
Lib/test/test_copy.py
Misc/ACKS
Misc/NEWS

index 264635042ca8953f3f93c0b8173eef07a82921d0..789488c1bc51e3782f8a5af2fdb944664b2edee0 100644 (file)
@@ -238,6 +238,10 @@ d[dict] = _deepcopy_dict
 if PyStringMap is not None:
     d[PyStringMap] = _deepcopy_dict
 
+def _deepcopy_method(x, memo): # Copy instance methods
+    return type(x)(x.__func__, deepcopy(x.__self__, memo))
+_deepcopy_dispatch[types.MethodType] = _deepcopy_method
+
 def _keep_alive(x, memo):
     """Keeps a reference to the object x in the memo.
 
index 2af21094eac2837271728ad3b6d8492dcea112e0..2df0deb7c8ee2ecdc85b9b1c1a1fa34a1de2f083 100644 (file)
@@ -677,6 +677,17 @@ class TestCopy(unittest.TestCase):
         del d
         self.assertEqual(len(v), 1)
 
+    def test_deepcopy_bound_method(self):
+        class Foo(object):
+            def m(self):
+                pass
+        f = Foo()
+        f.b = f.m
+        g = copy.deepcopy(f)
+        self.assertEqual(g.m, g.b)
+        self.assertTrue(g.b.__self__ is g)
+        g.b()
+
 
 def global_foo(x, y): return x+y
 
index 044224405efdc0a1dbe8efce28b83738f87ba6be..89a5fc47bc6fdfd63b5fa23f87294afb4abd8f00 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -144,6 +144,7 @@ Josh Cogliati
 Dave Cole
 Benjamin Collar
 Jeffery Collins
+Robert Collins
 Paul Colomiets
 Matt Conway
 David M. Cooke
index 4ca20ed96b0be90a5348a575f37777ad355da70d..3abf192ef9dd2e669f66c3fb0b25770c992b1733 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -140,6 +140,9 @@ C-API
 Library
 -------
 
+- Issue #1515: Enable use of deepcopy() with instance methods.  Patch by
+  Robert Collins.
+
 - Issue #7403: logging: Fixed possible race condition in lock creation.
 
 - Issue #6845: Add restart support for binary upload in ftplib.  The