Use a Python __reduce__ method to make pickles match C.
On it's own, this breaks on protocols >= 2 (including Python 3 by default) because the pickled object's class is required to match the reduce output. One fix would be to change the pickle format to use a custom constructor function, but then we'd have different pickle formats in C and Python. Rather than do that, we instead create a __class__ property for the python implementation. This bypasses the protocol limitations. The __class__ property wasn't assignable in the C implementation, so the compatibility risk should be very small. All the special pickle machinery is only defined in Python if needed.
Showing
This diff is collapsed.