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

Skip to content

Commit 25ea45d

Browse files
author
Kristján Valur Jónsson
committed
Merge with 3.3
2 parents d74ac82 + 4ca688e commit 25ea45d

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/test/test_range.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,18 @@ def test_iterator_pickling(self):
380380
it = pickle.loads(d)
381381
self.assertEqual(list(it), data[1:])
382382

383+
def test_exhausted_iterator_pickling(self):
384+
r = range(20)
385+
i = iter(r)
386+
while True:
387+
r = next(i)
388+
if r == 19:
389+
break
390+
d = pickle.dumps(i)
391+
i2 = pickle.loads(d)
392+
self.assertEqual(list(i), [])
393+
self.assertEqual(list(i2), [])
394+
383395
def test_odd_bug(self):
384396
# This used to raise a "SystemError: NULL result without error"
385397
# because the range validation step was eating the exception

Objects/rangeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ rangeiter_setstate(rangeiterobject *r, PyObject *state)
807807
long index = PyLong_AsLong(state);
808808
if (index == -1 && PyErr_Occurred())
809809
return NULL;
810-
if (index < 0 || index >= r->len) {
810+
if (index < 0 || index > r->len) {
811811
PyErr_SetString(PyExc_ValueError, "index out of range");
812812
return NULL;
813813
}

0 commit comments

Comments
 (0)