On Wed, May 27, 2009 at 03:35:26PM +0200, Hanno Schlichting wrote: > Marius Gedminas wrote: > > 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. > > Hhm, no. From what I read most objects are created by the following: > > class _EmptyClass: > pass > > value = _EmptyClass() > value.__class__ = klass > > > The "__new__" is only called when your new-style class has a > "__getnewargs__" method, which none of the standard types have. And even > then it would only be used for pickle protocol 2, but the ZODB uses > protocol 1.
It's an Internet Law that every correction must have at least one mistake. Mine was assuming that __new__ is always invoked. > > Old-style classes that define __getinitargs__ will get their __init__ > > called during unpickling, though, and DateTime is such a class. > > Ah, ok. I missed that this only happens in conjunction with > "__getinitargs__". Marius Gedminas -- Bumper sticker: No radio - Already stolen.
signature.asc
Description: Digital signature
_______________________________________________ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org http://mail.zope.org/mailman/listinfo/zodb-dev