Commit bfc87d39 authored by Pierre Glaser's avatar Pierre Glaser Committed by Stefan Behnel

Fix pickling unbound cython methods (GH-2969)

parent cb53a50c
......@@ -426,7 +426,8 @@ static PyObject *
__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
{
#if PY_MAJOR_VERSION >= 3
return PyUnicode_FromString(m->func.m_ml->ml_name);
Py_INCREF(m->func_qualname);
return m->func_qualname;
#else
return PyString_FromString(m->func.m_ml->ml_name);
#endif
......
......@@ -287,3 +287,20 @@ cdef class Wrapper(object):
return "Wrapper(...)"
else:
return "Wrapper(%r)" % self.ref
# Non-regression test for pickling bound and unbound methods of non-extension
# classes
if sys.version_info[:2] >= (3, 5):
# builtin methods not picklable for python <= 3.4
class MyClass(object):
"""
>>> import pickle
>>> pickle.loads(pickle.dumps(MyClass.my_method)) is MyClass.my_method
True
>>> bound_method = pickle.loads(pickle.dumps(MyClass().my_method))
>>> bound_method(1)
1
"""
def my_method(self, x):
return x
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment