[issue1515] deepcopy doesn't copy instance methods
Guido van Rossum
report at bugs.python.org
Thu Dec 20 00:03:17 CET 2007
Guido van Rossum added the comment:
I disagree that this would be harmless; this was excluded intentionally.
A (bound) method contains an instance which definitely represents state
and calling the method can easily mutate that state.
This is different from classes (which could contain state) or modules
(which almost certainly contain state) or functions (which could mutate
global state) -- in all those cases, we're talking about singleton
state, for which it makes sense not to create a clone. But for methods,
we're talking about instances, of which there could be many, and I
believe those should be properly copied or refused, rather than creating
accidental state sharing between the original and its deep copy.
I suppose you have a specific use case in mind. Can't you solve that by
adding a __deepcopy__ method to some object?
Tracker <report at bugs.python.org>
More information about the Python-bugs-list