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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
2c47e7d3
Commit
2c47e7d3
authored
May 16, 2017
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add directive to control pickling.
parent
9e98eaf9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
1 deletion
+14
-1
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+3
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+9
-1
tests/run/reduce_pickle.pyx
tests/run/reduce_pickle.pyx
+2
-0
No files found.
Cython/Compiler/Options.py
View file @
2c47e7d3
...
...
@@ -144,6 +144,7 @@ _directive_defaults = {
'embedsignature'
:
False
,
'locals'
:
{},
'auto_cpdef'
:
False
,
'auto_pickle'
:
None
,
'cdivision'
:
False
,
# was True before 0.12
'cdivision_warnings'
:
False
,
'overflowcheck'
:
False
,
...
...
@@ -263,6 +264,7 @@ def normalise_encoding_name(option_name, encoding):
# Override types possibilities above, if needed
directive_types
=
{
'auto_pickle'
:
bool
,
'final'
:
bool
,
# final cdef classes and methods
'internal'
:
bool
,
# cdef class visibility in the module dict
'infer_types'
:
bool
,
# values can be True/None/False
...
...
@@ -285,6 +287,7 @@ for key, val in _directive_defaults.items():
directive_scopes
=
{
# defaults to available everywhere
# 'module', 'function', 'class', 'with statement'
'auto_pickle'
:
(
'module'
,
'cclass'
),
'final'
:
(
'cclass'
,
'function'
),
'inline'
:
(
'function'
,),
'staticmethod'
:
(
'function'
,),
# FIXME: analysis currently lacks more specific function scope
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
2c47e7d3
...
...
@@ -1571,6 +1571,10 @@ if VALUE is not None:
def
_inject_pickle_methods
(
self
,
node
):
env
=
self
.
current_env
()
if
node
.
scope
.
directives
[
'auto_pickle'
]
is
False
:
# None means attempt it.
# Old behavior of not doing anything.
return
all_members
=
[]
cls
=
node
.
entry
.
type
cinit
=
None
...
...
@@ -1590,7 +1594,11 @@ if VALUE is not None:
# 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
)
msg
=
"%s cannot be converted to a Python object for pickling"
%
','
.
join
(
"self.%s"
%
e
.
name
for
e
in
non_py
)
if
node
.
scope
.
directives
[
'auto_pickle'
]
is
True
:
error
(
node
.
pos
,
msg
)
pickle_func
=
TreeFragment
(
u"""
def __reduce__(self):
raise TypeError("%s")
...
...
tests/run/reduce_pickle.pyx
View file @
2c47e7d3
import
cython
import
sys
if
sys
.
version_info
[
0
]
<
3
:
...
...
@@ -59,6 +60,7 @@ def makeB(kwds):
return
B
(
**
kwds
)
@
cython
.
auto_pickle
(
True
)
# Not needed, just to test the directive.
cdef
class
DefaultReduce
(
object
):
"""
>>> a = DefaultReduce(11, 'abc'); a
...
...
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