Michael Van Biesbrouck added the comment:
Dmitrey: You can't call _deepcopy_method() on anything other than
something with type types.MethodType. It is a function in a
type-dispatch table, so it will always be called safely.
copy._deepcopy_dispatch is that table; if you assign _deepcopy_m
Michael Van Biesbrouck added the comment:
Guido pointed out a common use case where people use bound methods in a
way that would be poorly served by my change. An alternate
implementation with a deeper copy will cause less surprise:
def _deepcopy_method(x, memo):
return type(x)(x.im_func
Michael Van Biesbrouck added the comment:
I am implementing a library that makes extensive use of delayed
executions represented by functions. Copying objects both with and
without shared state referenced by the functions is important. There is
one entry point where I would expect functions to
New submission from Michael Van Biesbrouck:
Currently, using deepcopy on instance methods causes an exception to be
thrown. This can be fixed by adding one line to copy.py:
d[types.MethodType] = _deepcopy_atomic
This will not make duplicate copies of mutable values referenced within
the