Skip to content

Commit 9862417

Browse files
committed
Don't allow MapMutation.update() calls after the mutation is finished
1 parent 0d6f144 commit 9862417

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

immutables/_map.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,6 +3880,10 @@ mapmut_py_update(MapMutationObject *self, PyObject *args, PyObject *kwds)
38803880
return NULL;
38813881
}
38823882

3883+
if (mapmut_check_finalized(self)) {
3884+
return NULL;
3885+
}
3886+
38833887
if (arg != NULL) {
38843888
if (map_update_inplace(self->m_mutid, (BaseMapObject *)self, arg)) {
38853889
return NULL;

immutables/map.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ def __contains__(self, key):
719719
return True
720720

721721
def update(self, col=None, **kw):
722+
if self.__mutid == 0:
723+
raise ValueError('mutation {!r} has been finished'.format(self))
724+
722725
it = None
723726
if col is not None:
724727
if hasattr(col, 'items'):

tests/test_map.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,9 @@ def test_map_mut_12(self):
11481148
with self.assertRaisesRegex(ValueError, 'has been finished'):
11491149
mm['a'] = 'b'
11501150

1151+
with self.assertRaisesRegex(ValueError, 'has been finished'):
1152+
mm.update(a='b')
1153+
11511154
def test_map_mut_13(self):
11521155
key1 = HashKey(123, 'aaa')
11531156
key2 = HashKey(123, 'aaa')

0 commit comments

Comments
 (0)