Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 898318b

Browse files
mmohrhardpitrou
authored andcommitted
bpo-37502: handle default parameter for buffers argument of pickle.loads correctly (GH-14593)
1 parent 93e8aa6 commit 898318b

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/test/pickletester.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,6 +2765,11 @@ def test_buffers_error(self):
27652765
with self.assertRaises(pickle.UnpicklingError):
27662766
self.loads(data, buffers=[])
27672767

2768+
def test_inband_accept_default_buffers_argument(self):
2769+
for proto in range(5, pickle.HIGHEST_PROTOCOL + 1):
2770+
data_pickled = self.dumps(1, proto, buffer_callback=None)
2771+
data = self.loads(data_pickled, buffers=None)
2772+
27682773
@unittest.skipIf(np is None, "Test needs Numpy")
27692774
def test_buffers_numpy(self):
27702775
def check_no_copy(x, y):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pickle.loads() no longer raises TypeError when the buffers argument is set to None

Modules/_pickle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ _Unpickler_SetInputEncoding(UnpicklerObject *self,
16531653
static int
16541654
_Unpickler_SetBuffers(UnpicklerObject *self, PyObject *buffers)
16551655
{
1656-
if (buffers == NULL) {
1656+
if (buffers == NULL || buffers == Py_None) {
16571657
self->buffers = NULL;
16581658
}
16591659
else {

0 commit comments

Comments
 (0)