Issue #1515: Enable use of deepcopy() with instance methods. Patch by Robert Collins.
diff --git a/Lib/copy.py b/Lib/copy.py
index d3db93d..bbbd5b3 100644
--- a/Lib/copy.py
+++ b/Lib/copy.py
@@ -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.