summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2019-07-25 16:00:34 (GMT)
committerAntoine Pitrou <antoine@python.org>2019-07-25 16:00:34 (GMT)
commit898318b53d921298d1f1fcfa0f415844afbeb318 (patch)
tree51c73d039d014c234366ec0b6b07baf61f175f55
parent93e8aa62cfd0a61efed4a61a2ffc2283ae986ef2 (diff)
downloadcpython-898318b53d921298d1f1fcfa0f415844afbeb318.zip
cpython-898318b53d921298d1f1fcfa0f415844afbeb318.tar.gz
cpython-898318b53d921298d1f1fcfa0f415844afbeb318.tar.bz2
bpo-37502: handle default parameter for buffers argument of pickle.loads correctly (GH-14593)
-rw-r--r--Lib/test/pickletester.py5
-rw-r--r--Misc/NEWS.d/next/Library/2019-07-08-03-15-04.bpo-37502.qZGC4g.rst1
-rw-r--r--Modules/_pickle.c2
3 files changed, 7 insertions, 1 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index f8f3bc9..2bc99e6 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -2765,6 +2765,11 @@ class AbstractPickleTests(unittest.TestCase):
with self.assertRaises(pickle.UnpicklingError):
self.loads(data, buffers=[])
+ def test_inband_accept_default_buffers_argument(self):
+ for proto in range(5, pickle.HIGHEST_PROTOCOL + 1):
+ data_pickled = self.dumps(1, proto, buffer_callback=None)
+ data = self.loads(data_pickled, buffers=None)
+
@unittest.skipIf(np is None, "Test needs Numpy")
def test_buffers_numpy(self):
def check_no_copy(x, y):
diff --git a/Misc/NEWS.d/next/Library/2019-07-08-03-15-04.bpo-37502.qZGC4g.rst b/Misc/NEWS.d/next/Library/2019-07-08-03-15-04.bpo-37502.qZGC4g.rst
new file mode 100644
index 0000000..4eb6d09
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-07-08-03-15-04.bpo-37502.qZGC4g.rst
@@ -0,0 +1 @@
+pickle.loads() no longer raises TypeError when the buffers argument is set to None
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 054276d..0c53f2e 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -1653,7 +1653,7 @@ _Unpickler_SetInputEncoding(UnpicklerObject *self,
static int
_Unpickler_SetBuffers(UnpicklerObject *self, PyObject *buffers)
{
- if (buffers == NULL) {
+ if (buffers == NULL || buffers == Py_None) {
self->buffers = NULL;
}
else {