Skip to content

Commit

Permalink
Fix cloudpipe#129: do not silence RuntimeError in dump() (cloudpipe#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou authored and HyukjinKwon committed Feb 6, 2018
1 parent 22af562 commit 3c2e52c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def dump(self, obj):
if 'recursion' in e.args[0]:
msg = """Could not pickle object as excessively deep recursion required."""
raise pickle.PicklingError(msg)
else:
raise

def save_memoryview(self, obj):
self.save(obj.tobytes())
Expand Down
15 changes: 15 additions & 0 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
HAVE_WEAKSET = hasattr(weakref, 'WeakSet')


class RaiserOnPickle(object):

def __init__(self, exc):
self.exc = exc

def __reduce__(self):
raise self.exc


def pickle_depickle(obj):
"""Helper function to test whether object pickled with cloudpickle can be
depickled with pickle
Expand Down Expand Up @@ -763,6 +772,12 @@ def test_function_pickle_compat_0_4_1(self):
b'\x14NtR.')
self.assertEquals(42, cloudpickle.loads(pickled)(42))

def test_pickle_reraise(self):
for exc_type in [Exception, ValueError, TypeError, RuntimeError]:
obj = RaiserOnPickle(exc_type("foo"))
with pytest.raises((exc_type, pickle.PicklingError)):
cloudpickle.dumps(obj)


if __name__ == '__main__':
unittest.main()

0 comments on commit 3c2e52c

Please sign in to comment.