Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
d33f4844
Commit
d33f4844
authored
May 15, 2017
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't generate __reduce__ when __cinit__ is non-trivial.
parent
2e84def5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+8
-2
tests/run/reduce_pickle.pyx
tests/run/reduce_pickle.pyx
+11
-0
No files found.
Cython/Compiler/ParseTreeTransforms.py
View file @
d33f4844
...
...
@@ -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):
...
...
tests/run/reduce_pickle.pyx
View file @
d33f4844
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment