Pickling extension types

Stefan Kuzminski stefan.kuzminski at gmail.com
Tue May 3 17:34:06 EDT 2011


Thanks for the clues, I made a modification so that reduce returns this..

  return Py_BuildValue("O(OOOOO)", Py_TYPE(self), PyTuple_New(0), Py_None,
Py_None, Py_None );

and now I get this different error when trying to pickle the type..

 ----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_missing.py", line 16, in test
    print cPickle.dumps( mv )
PicklingError: Can't pickle <type 'MV'>: attribute lookup __builtin__.MV
failed

thx,
S

One grep through the source later:
>
> >>> slice(1,2,3).__reduce__()
> (<type 'slice'>, (1, 2, 3))
>
> And the implementation seems straightforward:
>
> static PyObject *
> slice_reduce(PySliceObject* self)
> {
>    return Py_BuildValue("O(OOO)", Py_TYPE(self), self->start, self->stop,
> self->step);
> }
>
>
>
> (*) it uses __getnewargs__
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110503/95df1598/attachment.html>


More information about the Python-list mailing list