2009/12/15 Ram Rachum <cool-rr@cool-rr.com>:
MRAB <python@...> writes:
cool-RR wrote:
What do you think?
My own feeling is that this is a misuse of __deepcopy__: if you ask for a copy (of a mutable object) then you should get a copy (for immutable objects copying isn't necessary).
I agree it that the Persistent.__deecopy__ thing does smell like misuse on my part. However I'd be happy to hear any alternative suggestion you have on how to solve the problem I have.
Deepcopy is a very simple operation conceptually, there's no need to make it more complicated. How about implementing __deepcopy__ in your world state objects? Specify attributes that don't need copying. You can even use the Persistent class to signal that. Something like this (untested!): def __deepcopy__(self): new = self.__class__() for k,v in self.__dict__.iteritems(): setattr(new, k, v if isinstance(v, Persistent) else deepcopy(v)) return new Vitor