summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ParseTreeTransforms.py
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@gmail.com>2017-05-16 12:20:04 -0700
committerRobert Bradshaw <robertwb@gmail.com>2017-05-16 12:20:04 -0700
commit2c47e7d30c15a3c40bc9d28c49abe92e9189092c (patch)
tree03718d5024b0f9f6df7a884547606db0a53578bb /Cython/Compiler/ParseTreeTransforms.py
parent9e98eaf9a9162cef9b016dc4d10a16d9b2c36a7e (diff)
downloadcython-2c47e7d30c15a3c40bc9d28c49abe92e9189092c.tar.gz
Add directive to control pickling.
Diffstat (limited to 'Cython/Compiler/ParseTreeTransforms.py')
-rw-r--r--Cython/Compiler/ParseTreeTransforms.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py
index bc739e33a..d5159234a 100644
--- a/Cython/Compiler/ParseTreeTransforms.py
+++ b/Cython/Compiler/ParseTreeTransforms.py
@@ -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")