Skip to content

Commit

Permalink
Fix #129: do not silence RuntimeError in dump() (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou authored and rgbkrk committed Feb 6, 2018
1 parent 216e841 commit 1105da1
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 @@ -50,6 +50,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 @@ -820,6 +829,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 1105da1

Please sign in to comment.