From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 25 Jul 2019 16:18:20 +0000 (-0700) Subject: bpo-37502: handle default parameter for buffers argument of pickle.loads correctly... X-Git-Tag: v3.8.0b3~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=25cb4fd4fb0f44d2b6bf38379634f3d22b77aa17;p=thirdparty%2FPython%2Fcpython.git bpo-37502: handle default parameter for buffers argument of pickle.loads correctly (GH-14593) (cherry picked from commit 898318b53d921298d1f1fcfa0f415844afbeb318) Co-authored-by: Markus Mohrhard --- diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index f8f3bc92e7fe..2bc99e6becfd 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 000000000000..4eb6d0974bde --- /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 0a597575b358..bbe26034881a 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 {