[Python-Dev] removing inst_persistent_id from pickle
Jeremy Hylton
jeremy@alum.mit.edu
Wed, 13 Nov 2002 11:16:36 -0500
Pickle and cPickle have an undocumented hook called
inst_persistent_id(). When Barry updated the pickle documentation
(round about the 2.2 release), no one could figure out what it did. I
think we've figured out what it does, finally, but I think we should
get rid of it before someone tries to use it.
The pickler has a hook for handling persistent objects. The hook
basically allows objects to be pickled by reference to some mechanism
external to the pickler. The pickler gets a persistent_id() function
that returns the external reference. The unpickler needs a
persistent_load() function that returns the object given the reference
from persistent_id(). This process is fairly general, although the
only use I'm familiar with is ZODB.
The inst_persistent_id() hook seems to be designed for a very special
case -- that the persistent_id() function returns an object that is
unpicklable. The function is only called when the pickler encounters
an object that it hasn't handled via persistent_id() or the dispatch
table. The object returned by inst_persistent_id() is always passed
to save_pers(), just like persistent_id().
We imagine the intended control flow is:
- pickler created in binary mode
- persistent_id() returns an unpicklable object
- inst_persistent_id() is called to convert this to a picklable
object
I don't think this odd case is worth the added complexity,
particularly since the hook function probably won't be called for a
text-mode pickler.
Anyone object to its removal?
Jeremy