=== modified file 'Lib/copy.py' --- Lib/copy.py 2009-05-15 16:54:52 +0000 +++ Lib/copy.py 2009-11-27 23:02:13 +0000 @@ -260,6 +260,10 @@ if PyStringMap is not None: d[PyStringMap] = _deepcopy_dict +def _deepcopy_method(x, memo): # Copy instance methods + return type(x)(x.im_func, deepcopy(x.im_self, memo), x.im_class) +_deepcopy_dispatch[types.MethodType] = _deepcopy_method + def _keep_alive(x, memo): """Keeps a reference to the object x in the memo. === modified file 'Lib/test/test_copy.py' --- Lib/test/test_copy.py 2009-06-30 22:57:08 +0000 +++ Lib/test/test_copy.py 2009-11-27 23:03:46 +0000 @@ -672,6 +672,17 @@ 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.im_self is g) + g.b() + def global_foo(x, y): return x+y