Skip to content

Pickling objects with __slots__ fails #225

Description

@sk1p

The following minimal test case:

diff --git a/tests/cloudpickle_test.py b/tests/cloudpickle_test.py
index d318da7..fec779c 100644
--- a/tests/cloudpickle_test.py+++ b/tests/cloudpickle_test.py@@ -1310,6 +1310,17 @@ class CloudPickleTest(unittest.TestCase):
self.assertEqual(f2.__annotations__, f.__annotations__)
+ def test_slots(self):+ class WithSlots(object):+ __slots__ = ["a"]++ def __init__(self):+ self.a = 42++ obj = WithSlots()+ obj2 = pickle_depickle(obj, protocol=self.protocol)+ self.assertEqual(obj2.a, 42)+
class Protocol2CloudPickleTest(CloudPickleTest):

Fails with this exception:

obj = <tests.cloudpickle_test.CloudPickleTest.test_slots.<locals>.WithSlots object at 0x7f5cdc8f94c8>, protocol = 4
def pickle_depickle(obj, protocol=cloudpickle.DEFAULT_PROTOCOL):
"""Helper function to test whether object pickled with cloudpickle can be
depickled with pickle
"""
> return pickle.loads(cloudpickle.dumps(obj, protocol=protocol))
E AttributeError: type object 'WithSlots' has no attribute 'a'
obj = <tests.cloudpickle_test.CloudPickleTest.test_slots.<locals>.WithSlots object at 0x7f5cdc8f94c8>
protocol = 4

Pickling with pickle from the standard library works.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions