From a62d920da89b127115d23198c47a6fd181a734df Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 13 Dec 2017 16:27:30 +0100 Subject: [PATCH] Fix #129: do not silence RuntimeError in dump() --- cloudpickle/cloudpickle.py | 2 ++ tests/cloudpickle_test.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/cloudpickle/cloudpickle.py b/cloudpickle/cloudpickle.py index e5aab0591..82a5717e1 100644 --- a/cloudpickle/cloudpickle.py +++ b/cloudpickle/cloudpickle.py @@ -270,6 +270,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()) diff --git a/tests/cloudpickle_test.py b/tests/cloudpickle_test.py index 23cbb3dbc..44bb93709 100644 --- a/tests/cloudpickle_test.py +++ b/tests/cloudpickle_test.py @@ -47,6 +47,15 @@ from .testutils import assert_run_python_script +class RaiserOnPickle(object): + + def __init__(self, exc): + self.exc = exc + + def __reduce__(self): + raise self.exc + + def pickle_depickle(obj, protocol=cloudpickle.DEFAULT_PROTOCOL): """Helper function to test whether object pickled with cloudpickle can be depickled with pickle @@ -862,6 +871,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) + class Protocol2CloudPickleTest(CloudPickleTest):