On Wed, May 27, 2009 at 12:17:36PM +0200, Hanno Schlichting wrote:
> Chris Withers wrote:
> > Hanno Schlichting wrote:
> >> They are incredibly expensive to unpickle since all
> >> the DWIM magic in their __init__ get called each time, though.
> > 
> > How come? Unpickling doesn't call __init__ and I don't see why the DWIM 
> > magic would be needed anyway, since everything has already been parsed.
> How would a new instance of a class be constructed without calling the
> init or new?

You're cleverly changing the question ;-)

*Most* objects are unpickled by calling __new__ followed by
__setstate__, but without calling __init__.  Chris is therefore
understandably surprised.

Old-style classes that define __getinitargs__ will get their __init__
called during unpickling, though, and DateTime is such a class.

You could also cause the __init__ to be called by defining __reduce__
or __reduce_ex__ appropriately.  This is all described in great detail
at http://python.org/doc/current/library/pickle.html#pickle-protocol

>Look at the _instantiate method in pickle.py, when it does:
> value = klass(*args)
> What happens on unpickling is that a new DateTime instance representing
> "just now" is generated and then that instance is updated with the
> values from the pickle.

Marius Gedminas
Every nonempty totally-disconnected perfect compact metric space is
homeomorphic to the Cantor set.

Attachment: signature.asc
Description: Digital signature

For more information about ZODB, see the ZODB Wiki:

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to