Commit d33f4844 authored by Robert Bradshaw's avatar Robert Bradshaw

Don't generate __reduce__ when __cinit__ is non-trivial.

parent 2e84def5
......@@ -1571,8 +1571,10 @@ if VALUE is not None:
env = self.current_env()
all_members = []
cls = node.entry.type
cinit = None
while cls is not None:
all_members.extend(cls.scope.var_entries)
cinit = cinit or cls.scope.lookup('__cinit__')
cls = cls.base_type
all_members.sort(key=lambda e: e.name)
......@@ -1581,7 +1583,11 @@ if VALUE is not None:
if not e.type.is_pyobject and (not e.type.create_from_py_utility_code(env)
or not e.type.create_to_py_utility_code(env))]
if non_py:
if cinit or non_py:
if cinit:
# TODO(robertwb): We could allow this if __cinit__ has no require arguments.
msg = 'no default __reduce__ due to non-trivial __cinit__'
else:
msg = "%s cannot be converted to a Python object" % ','.join("self.%s" % e.name for e in non_py)
pickle_func = TreeFragment(u"""
def __reduce__(self):
......
......@@ -107,3 +107,14 @@ cdef class NoReduceDueToIntPtr(object):
TypeError: self.int_ptr cannot be converted to a Python object
"""
cdef int* int_ptr
cdef class NoReduceDueToNontrivialCInit(object):
"""
>>> import pickle
>>> pickle.dumps(NoReduceDueToNontrivialCInit(None))
Traceback (most recent call last):
...
TypeError: no default __reduce__ due to non-trivial __cinit__
"""
def __cinit__(self, arg):
pass
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