Pickling slotted instances
Martin v. Loewis
martin at v.loewis.de
Mon Sep 16 07:37:23 CEST 2002
Andrew McNamara <andrewm at object-craft.com.au> writes:
> I'm really just wondering what makes the solution space large: my
> superficial understanding suggests all the necessary information is
> readily available for serialising the object's state (but I can see
> metaclasses make it complex).
I don't know what issues Guido had in mind, but here are a few for
1. How to determine all slots? It has been proposed that __slots__
should return a tuple that includes base slots as well;
alternatively, iterate over base types yourself. Alternatively,
return slots in __dict__.
2. Should all slots be pickled unconditionally? You seem to expect
this, but Samuele Pedroni points out that, in Java, some slots can
be marked transient, to avoid pickling them.
3. How to pickle slots? You are suggesting that the list of slot names
is included, but that appears to be redundant - if you know the type,
you also know what slots it has.
4. How to pickle unset slots? If a type has a slot but the instance
has not assigned the slot, requesting the slot value raises an
If you are in doubt that this is really as tricky as presented, I'd
encourage you to come up with a patch. In the process of implementing
the patch, you may either find that all issues have a straight-forward
solution, or that there are really serious issues remaining.
More information about the Python-list