Skip to content

Commit 67c977b

Browse files
Joe Jevnikrgbkrk
authored andcommitted
BUG: itertools objects are actually picklable
1 parent fc339d2 commit 67c977b

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

cloudpickle/cloudpickle.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,6 @@ def save_buffer(self, obj):
284284

285285
dispatch[buffer] = save_buffer
286286

287-
def save_unsupported(self, obj):
288-
raise pickle.PicklingError("Cannot pickle objects of type %s" % type(obj))
289-
290-
dispatch[types.GeneratorType] = save_unsupported
291-
292-
# itertools objects do not pickle!
293-
for v in itertools.__dict__.values():
294-
if type(v) is type:
295-
dispatch[v] = save_unsupported
296-
297287
def save_module(self, obj):
298288
"""
299289
Save a module as an import

tests/cloudpickle_test.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,6 @@ def test_ufunc(self):
347347
else: # skip if scipy is not available
348348
pass
349349

350-
def test_save_unsupported(self):
351-
sio = StringIO()
352-
pickler = cloudpickle.CloudPickler(sio, 2)
353-
354-
with pytest.raises(pickle.PicklingError) as excinfo:
355-
pickler.save_unsupported("test")
356-
357-
assert "Cannot pickle objects of type" in str(excinfo.value)
358-
359350
def test_loads_namespace(self):
360351
obj = 1, 2, 3, 4
361352
returned_obj = cloudpickle.loads(cloudpickle.dumps(obj))
@@ -883,6 +874,20 @@ def test_unhashable_function(self):
883874
self.assertEquals(depickled_method('a'), 1)
884875
self.assertEquals(depickled_method('b'), None)
885876

877+
def test_itertools_count(self):
878+
counter = itertools.count(1, step=2)
879+
880+
# advance the counter a bit
881+
next(counter)
882+
next(counter)
883+
884+
new_counter = pickle_depickle(counter, protocol=self.protocol)
885+
886+
self.assertTrue(counter is not new_counter)
887+
888+
for _ in range(10):
889+
self.assertEqual(next(counter), next(new_counter))
890+
886891

887892
class Protocol2CloudPickleTest(CloudPickleTest):
888893

0 commit comments

Comments
 (0)