pickle question: sequencing of operations
Russell E. Owen
rowen at uw.edu
Wed May 9 15:39:05 EDT 2012
In article
<CALwzidk3e353cnuUQPwr-4rRomX7C9DbZaPAwurerN9UZYuaBA at mail.gmail.com>,
Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen <rowen at uw.edu> wrote:
> > In article <rowen-DF116B.12542704052012 at news.gmane.org>,
> > "Russell E. Owen" <rowen at uw.edu> wrote:
> >
> >> What is the sequence of calls when unpickling a class with __setstate__?
>
> I believe it just calls object.__new__ followed by
> yourclass.__setstate__. So at the point __setstate__ is called, you
> have a pristine instance of whatever class you're unpickling.
I was wondering. I override __new__ (and __init__) to print messages and
was quite surprised to only see __new__being called when the object was
first created, not when it was being unpickled. But maybe there's
something funny about my override that caused unpickle to ignore it and
use the default version. I hope so. I can't see how the object could be
constructed during unpickle without calling __new__. But that's one
reason I was curious about the unpickling sequence of operations.
-- Russell
More information about the Python-list
mailing list