Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ def test_iterator_setstate(self):
it.__setstate__(2**64 - 7)
self.assertEqual(list(it), [12, 10])

msg = "'float' object cannot be interpreted as an integer"
with self.assertRaisesRegex(TypeError, msg):
it = iter(range(10, 100, 2))
it.__setstate__(1.0)

with self.assertRaisesRegex(TypeError, msg):
it = iter(range(10, 2**65, 2))
it.__setstate__(1.0)

def test_odd_bug(self):
# This used to raise a "SystemError: NULL result without error"
# because the range validation step was eating the exception
Expand Down
6 changes: 6 additions & 0 deletions Objects/rangeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,12 @@ longrangeiter_setstate(PyObject *op, PyObject *state)
PyObject *product = PyNumber_Multiply(state, r->step);
if (product == NULL)
return NULL;
if (!PyLong_Check(product)) {
Py_DECREF(product);
PyErr_Format(PyExc_TypeError,
"'%T' object cannot be interpreted as an integer", state);
return NULL;
}
PyObject *new_start = PyNumber_Add(r->start, product);
Py_DECREF(product);
if (new_start == NULL)
Expand Down
Loading