mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #14288: Serialization support for builtin iterators.
This commit is contained in:
parent
283b96b6bd
commit
31668b8f7a
28 changed files with 2190 additions and 104 deletions
|
@ -9,6 +9,7 @@ from random import randrange, shuffle
|
|||
import sys
|
||||
import warnings
|
||||
import collections
|
||||
import collections.abc
|
||||
|
||||
class PassThru(Exception):
|
||||
pass
|
||||
|
@ -234,6 +235,26 @@ class TestJointOps(unittest.TestCase):
|
|||
dup = pickle.loads(p)
|
||||
self.assertEqual(self.s.x, dup.x)
|
||||
|
||||
def test_iterator_pickling(self):
|
||||
itorg = iter(self.s)
|
||||
data = self.thetype(self.s)
|
||||
d = pickle.dumps(itorg)
|
||||
it = pickle.loads(d)
|
||||
# Set iterators unpickle as list iterators due to the
|
||||
# undefined order of set items.
|
||||
# self.assertEqual(type(itorg), type(it))
|
||||
self.assertTrue(isinstance(it, collections.abc.Iterator))
|
||||
self.assertEqual(self.thetype(it), data)
|
||||
|
||||
it = pickle.loads(d)
|
||||
try:
|
||||
drop = next(it)
|
||||
except StopIteration:
|
||||
return
|
||||
d = pickle.dumps(it)
|
||||
it = pickle.loads(d)
|
||||
self.assertEqual(self.thetype(it), data - self.thetype((drop,)))
|
||||
|
||||
def test_deepcopy(self):
|
||||
class Tracer:
|
||||
def __init__(self, value):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue