En Fri, 05 Feb 2010 11:25:02 -0300, Gaetan de Menten <gdemen...@gmail.com>
escribió:

I am trying to write an (optional!) C extension for SQLAlchemy, and I
am struggling to make an extension type picklable *and* using the same
format as the pure Python version (so that computers with the C
extension can unpickle pickles from computers without it and
vice-versa). [...]
My last hope is to define __reduce__ on the Python
side too,

That seems reasonable.

and make it use a module-level "reconstructor" function as
follow:

def mypythontype_reconstructor(cls, state):
    obj = object.__new__(cls, state):
    ....
    return obj

Will this work? Any other idea?

If you're going to call object.__new__(cls, state) anyway, then just
return the object's type as the first item in __reduce__; no need to
create such global function


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to