-
Notifications
You must be signed in to change notification settings - Fork 61
Description
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:
- https://cython.readthedocs.io/en/latest/src/userguide/extension_types.html
- https://docs.python.org/3/extending/newtypes_tutorial.html
- support __new__() in extension types cython/cython#799
- https://github.com/cython/cython/blob/fcfd16c7467c31f255287a73f36cf66b32bc096c/Cython/Compiler/Symtab.py#L2291
- result type of calling an extension type is unknown cython/cython#793
- https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html