=== modified file 'Lib/copy.py' --- Lib/copy.py 2009-05-15 16:54:52 +0000 +++ Lib/copy.py 2009-11-27 09:54:12 +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. @@ -413,5 +417,14 @@ print map(repr.repr, l2) print map(repr.repr, l3) + class Foo(object): + def m(self): + pass + f = Foo() + f.b = f.m + g = deepcopy(f) + assert g.m == g.b + assert g.m.im_self is g + if __name__ == '__main__': _test()