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

Skip to content

Commit b46a633

Browse files
author
Hirokazu Yamamoto
committed
Sorry, r67092 is commit miss....
1 parent 1543a22 commit b46a633

2 files changed

Lines changed: 8 additions & 21 deletions

File tree

Lib/pickle.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,6 @@ def save_pers(self, pid):
345345
else:
346346
self.write(PERSID + str(pid).encode("ascii") + b'\n')
347347

348-
def _isiter(self, obj):
349-
return hasattr(obj, '__next__') and hasattr(obj, '__iter__')
350-
351348
def save_reduce(self, func, args, state=None,
352349
listitems=None, dictitems=None, obj=None):
353350
# This API is called by some subclasses
@@ -360,16 +357,6 @@ def save_reduce(self, func, args, state=None,
360357
if not hasattr(func, '__call__'):
361358
raise PicklingError("func from save_reduce() should be callable")
362359

363-
# Assert that listitems is an iterator
364-
if listitems is not None and not self._isiter(listitems):
365-
raise PicklingError("listitems from save_reduce() should be an "
366-
"iterator")
367-
368-
# Assert that dictitems is an iterator
369-
if dictitems is not None and not self._isiter(dictitems):
370-
raise PicklingError("dictitems from save_reduce() should be an "
371-
"iterator")
372-
373360
save = self.save
374361
write = self.write
375362

Modules/_pickle.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,13 +1963,21 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
19631963
PyObject *state = NULL;
19641964
PyObject *listitems = Py_None;
19651965
PyObject *dictitems = Py_None;
1966+
Py_ssize_t size;
19661967

19671968
int use_newobj = self->proto >= 2;
19681969

19691970
const char reduce_op = REDUCE;
19701971
const char build_op = BUILD;
19711972
const char newobj_op = NEWOBJ;
19721973

1974+
size = PyTuple_Size(args);
1975+
if (size < 2 || size > 5) {
1976+
PyErr_SetString(PicklingError, "tuple returned by "
1977+
"__reduce__ must contain 2 through 5 elements");
1978+
return -1;
1979+
}
1980+
19731981
if (!PyArg_UnpackTuple(args, "save_reduce", 2, 5,
19741982
&callable, &argtup, &state, &listitems, &dictitems))
19751983
return -1;
@@ -2146,7 +2154,6 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
21462154
PyObject *reduce_value = NULL;
21472155
PyObject *memo_key = NULL;
21482156
int status = 0;
2149-
Py_ssize_t size;
21502157

21512158
if (Py_EnterRecursiveCall(" while pickling an object") < 0)
21522159
return -1;
@@ -2325,13 +2332,6 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
23252332
goto error;
23262333
}
23272334

2328-
size = PyTuple_Size(reduce_value);
2329-
if (size < 2 || size > 5) {
2330-
PyErr_SetString(PicklingError, "tuple returned by "
2331-
"__reduce__ must contain 2 through 5 elements");
2332-
goto error;
2333-
}
2334-
23352335
status = save_reduce(self, reduce_value, obj);
23362336

23372337
if (0) {

0 commit comments

Comments
 (0)