diff options
author | Yury Selivanov <yury@magic.io> | 2018-12-13 16:21:46 -0500 |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2018-12-13 16:21:46 -0500 |
commit | 9862417e80ada753c85dcc127724843f5c8bc989 (patch) | |
tree | 43e18fc6c79faa1a6b8286302454c6bbc39d9e54 | |
parent | 0d6f144fcd9f2060153908878e23ab466ffefa44 (diff) | |
download | immutables-9862417e80ada753c85dcc127724843f5c8bc989.tar.gz immutables-9862417e80ada753c85dcc127724843f5c8bc989.zip |
Don't allow MapMutation.update() calls after the mutation is finished
-rw-r--r-- | immutables/_map.c | 4 | ||||
-rw-r--r-- | immutables/map.py | 3 | ||||
-rw-r--r-- | tests/test_map.py | 3 |
3 files changed, 10 insertions, 0 deletions
diff --git a/immutables/_map.c b/immutables/_map.c index 9a81556..9b406ea 100644 --- a/immutables/_map.c +++ b/immutables/_map.c @@ -3880,6 +3880,10 @@ mapmut_py_update(MapMutationObject *self, PyObject *args, PyObject *kwds) return NULL; } + if (mapmut_check_finalized(self)) { + return NULL; + } + if (arg != NULL) { if (map_update_inplace(self->m_mutid, (BaseMapObject *)self, arg)) { return NULL; diff --git a/immutables/map.py b/immutables/map.py index 7b230dd..4c5cd49 100644 --- a/immutables/map.py +++ b/immutables/map.py @@ -719,6 +719,9 @@ class MapMutation: return True def update(self, col=None, **kw): + if self.__mutid == 0: + raise ValueError('mutation {!r} has been finished'.format(self)) + it = None if col is not None: if hasattr(col, 'items'): diff --git a/tests/test_map.py b/tests/test_map.py index 66d07e7..a99b856 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -1148,6 +1148,9 @@ class BaseMapTest: with self.assertRaisesRegex(ValueError, 'has been finished'): mm['a'] = 'b' + with self.assertRaisesRegex(ValueError, 'has been finished'): + mm.update(a='b') + def test_map_mut_13(self): key1 = HashKey(123, 'aaa') key2 = HashKey(123, 'aaa') |