I tried this code:

static PyObject *
frozendict_reduce(PyFrozenDictObject* mp, PyObject *Py_UNUSED(ignored))
{
    PyObject* args = PyTuple_New(1);

    if (args == NULL) {
        return NULL;
    }

    PyTuple_SET_ITEM(args, 0, (PyObject *)mp);

    PyObject *d = PyObject_Call((PyObject *)&PyDict_Type, args, NULL);
    Py_INCREF(mp);
    return Py_BuildValue("O(N)", Py_TYPE(mp), d);
}

but I get:
_pickle.PicklingError: Can't pickle <class 'frozendict'>: attribute lookup
frozendict on builtins failed

The identical (?) Python code works:


def __reduce__(self, *args, **kwargs):
    return (self.__class__, (dict(self), ))
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to