PEP 285 and pickle compatibility

Paul Rubin phr-n2002a at nightsong.com
Fri Apr 5 07:37:05 EST 2002


Paul Rubin <phr-n2002a at nightsong.com> writes:
> Proposed fix: in new pickles, dump boolean True as "I01" and boolean
> False as "I00".  The current unpickler should load these as the integer
> values 1 and 0 and everything should work fine.  But these strings
> will never be generated by the current pickler, which wouldn't emit
> the leading 0's.  

I should have mentioned:

Note that if the old and new python versions are sending pickles to
each other, and the old version unpickles a bool under this scheme
and then repickles it and sends it back, the object's booleanness
will be lost.  The new version will send True and get back integer 1.

That's probably preferable default behavior to making a pickle that
old versions can't read; however, sometimes, it may not be the right
thing.  I guess a flag (i.e. the format code described earlier) passed
to the dump function should control what happens.

I can see some other possible ways to handle all this too.

It really should have been discussed in more detail in the PEP.



More information about the Python-list mailing list