[ZODB-Dev] __setstate__
Neil Schemenauer
nas@mems-exchange.org
Thu, 28 Mar 2002 14:06:38 -0500
On Wed, Mar 27, 2002 at 10:43:49PM +0100, Magnus Lyck? wrote:
> I have a number of classes that subclass Persistence.Persistent.
>
> I want to upgrade attributes for some of them, and understand
> that I should do this in __setstate__.
Yes.
> Can someone give an example of how to do this?
class MyObject(Persistent):
...
def __setstate__(self, dict):
self.__dict__.update(dict)
<do other things with MyObject instance>
...
> Do I need to call __setstate__ of a base class (Persistence.Persistent)
> in my own __setstate__?
Not necessary.
> Should I do something about __getstate__ as well?
Nope.
> Are there any particular gotchas or better alternatives?
Changes that you make in the __setstate__ will not dirty the object.
Neil