From 339d62fadafd0ab35a6394c2ad210b092704ce98 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Tue, 20 Nov 2018 14:12:57 -0500 Subject: Make MapMutation unpickleable --- immutables/map.py | 3 +++ tests/test_map.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/immutables/map.py b/immutables/map.py index 73581ed..fc40ac8 100644 --- a/immutables/map.py +++ b/immutables/map.py @@ -722,6 +722,9 @@ class MapMutation: def __len__(self): return self.__count + def __reduce__(self): + raise TypeError("can't pickle {} objects".format(type(self).__name__)) + def __hash__(self): raise TypeError('unhashable type: {}'.format(type(self).__name__)) diff --git a/tests/test_map.py b/tests/test_map.py index d7ee885..959e00c 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -1254,6 +1254,9 @@ class BaseMapTest: self.assertTrue(isinstance(uh, self.Map)) self.assertEqual(h, uh) + with self.assertRaisesRegex(TypeError, "can't pickle"): + pickle.dumps(h.mutate()) + class PyMapTest(BaseMapTest, unittest.TestCase): -- cgit v1.2.3