mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Make the various iterators' "setstate" sliently and consistently clip the
index. This avoids the possibility of setting an iterator to an invalid state.
This commit is contained in:
commit
c5cc5011ac
8 changed files with 66 additions and 15 deletions
|
@ -381,6 +381,18 @@ class RangeTest(unittest.TestCase):
|
|||
self.assertEqual(list(it), data[1:])
|
||||
|
||||
def test_exhausted_iterator_pickling(self):
|
||||
r = range(2**65, 2**65+2)
|
||||
i = iter(r)
|
||||
while True:
|
||||
r = next(i)
|
||||
if r == 2**65+1:
|
||||
break
|
||||
d = pickle.dumps(i)
|
||||
i2 = pickle.loads(d)
|
||||
self.assertEqual(list(i), [])
|
||||
self.assertEqual(list(i2), [])
|
||||
|
||||
def test_large_exhausted_iterator_pickling(self):
|
||||
r = range(20)
|
||||
i = iter(r)
|
||||
while True:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue