[ZODB-Dev] persisting "immutable" classes

Tim Peters tim at zope.com
Sun Feb 29 03:59:00 EST 2004


[Tim Peters]
>> It's unclear why you need your own {get,set)state functions.
>> Automagic pickle support for new-style objects with __slots__ was
>> added in Python 2.3, as described (in excruciating detail) here:
>>
>>     http://www.python.org/peps/pep-0307.html
>>
>> The magical __slots__ support requires using the new-in-2.3 "pickle
>> protocol 2"; that protocol also allows pickle to do lots of other
>> things in better ways for new-style classes.

[John Belmonte]
> When I try using slots on a second-class persistent object, the new
> pickle protocol doesn't seem to be getting used.  After reading the
> PEP, it's unclear to me how to specify protocol 2 for a given class.
> What are my options?

Now that you mention it <wink>, you probably have no options -- the call
that creates a cPickle.Pickler specifies the protocol, ZODB internals do
that, and it looks like they're all hard-coded to 1 now.

It would mostly be a Good Thing to use proto 2 instead, except then
databases would have no chance of being readable under versions of Python
before 2.3 (trying to would die with "invalid load key" exceptions coming
out of cPickle -- Python version J can read pickles created by all Python
versions I with I <= J, but older versions can't read pickles using newer
features).

So we might be able to get away with switching to proto 2 in ZODB 3.3, but
not in the 3.1 or 3.2 lines.




More information about the ZODB-Dev mailing list