Skip to content

Commit

Permalink
bpo-37502: handle default parameter for buffers argument of pickle.lo…
Browse files Browse the repository at this point in the history
…ads correctly (pythonGH-14593)
  • Loading branch information
mmohrhard authored and websurfer5 committed Jul 20, 2020
1 parent 2f8e7a5 commit 726b16f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Lib/test/pickletester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2765,6 +2765,11 @@ def test_buffers_error(self):
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pickle.loads() no longer raises TypeError when the buffers argument is set to None
2 changes: 1 addition & 1 deletion Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 726b16f

Please sign in to comment.