[pypy-commit] pypy default: make error message compliant with cPickle, low hanging fruit

mattip pypy.commits at gmail.com
Mon Aug 21 06:46:09 EDT 2017


Author: Matti Picus <matti.picus at gmail.com>
Branch: 
Changeset: r92196:52ae4608d26f
Date: 2017-08-21 13:43 +0300
http://bitbucket.org/pypy/pypy/changeset/52ae4608d26f/

Log:	make error message compliant with cPickle, low hanging fruit

diff --git a/lib_pypy/cPickle.py b/lib_pypy/cPickle.py
--- a/lib_pypy/cPickle.py
+++ b/lib_pypy/cPickle.py
@@ -116,10 +116,20 @@
 
 @builtinify
 def dump(obj, file, protocol=None):
+    if protocol > HIGHEST_PROTOCOL:
+        # use cPickle error message, not pickle.py one
+        raise ValueError("pickle protocol %d asked for; "
+                     "the highest available protocol is %d" % (
+                     protocol, HIGHEST_PROTOCOL))
     Pickler(file, protocol).dump(obj)
 
 @builtinify
 def dumps(obj, protocol=None):
+    if protocol > HIGHEST_PROTOCOL:
+        # use cPickle error message, not pickle.py one
+        raise ValueError("pickle protocol %d asked for; "
+                     "the highest available protocol is %d" % (
+                     protocol, HIGHEST_PROTOCOL))
     file = StringIO()
     Pickler(file, protocol).dump(obj)
     return file.getvalue()


More information about the pypy-commit mailing list