[Python-ideas] Being able to specify

Vitor Bosshard algorias at gmail.com
Tue Dec 15 18:28:12 CET 2009

2009/12/15 Ram Rachum <cool-rr at cool-rr.com>:
> Vitor Bosshard <algorias at ...> writes:
>> 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
> And what happens when State refers to another object which refers to a
> Persistent?

Then that object would need to implement the same method, perhaps by
inheriting form a common base. The point is that it can be done in a
straightforward manner without needing to change the stdlib.


More information about the Python-ideas mailing list