mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Fix pickling of rangeiter. rangeiter_setstate would not allow setting it
to the exhausted state.
This commit is contained in:
parent
682ea5f70e
commit
4ca688edeb
2 changed files with 13 additions and 1 deletions
|
|
@ -379,6 +379,18 @@ class RangeTest(unittest.TestCase):
|
|||
it = pickle.loads(d)
|
||||
self.assertEqual(list(it), data[1:])
|
||||
|
||||
def test_exhausted_iterator_pickling(self):
|
||||
r = range(20)
|
||||
i = iter(r)
|
||||
while True:
|
||||
r = next(i)
|
||||
if r == 19:
|
||||
break
|
||||
d = pickle.dumps(i)
|
||||
i2 = pickle.loads(d)
|
||||
self.assertEqual(list(i), [])
|
||||
self.assertEqual(list(i2), [])
|
||||
|
||||
def test_odd_bug(self):
|
||||
# This used to raise a "SystemError: NULL result without error"
|
||||
# because the range validation step was eating the exception
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue