The way pickle persists C extension types (including objects created by cython) is to rely on __reduce__ and __reduce_ex__.
We should find a protocol that third party packages can implement, so that we could avoid relying on __reduce__.
One issue is that we can't call __new__ on C extension types generated by Cython. Cython would raise if the type tries to implement this special method. However, one can implement __cinit__ in cython.
We can certainly require those objects to implement __getstate__ and __setstate__. The remaining issue is the constructor.
Right now we call __new__ for all other objects, but we can't do that here. The question is, should we then call Object() instead? Or should we find a way to have something which acts as a low level and light constructor.
Some links:
The way pickle persists C extension types (including objects created by cython) is to rely on
__reduce__and__reduce_ex__.We should find a protocol that third party packages can implement, so that we could avoid relying on
__reduce__.One issue is that we can't call
__new__on C extension types generated by Cython. Cython would raise if the type tries to implement this special method. However, one can implement__cinit__in cython.We can certainly require those objects to implement
__getstate__and__setstate__. The remaining issue is the constructor.Right now we call
__new__for all other objects, but we can't do that here. The question is, should we then callObject()instead? Or should we find a way to have something which acts as a low level and light constructor.Some links: