aboutsummaryrefslogtreecommitdiff
path: root/immutables
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-04-03 00:01:41 -0400
committerYury Selivanov <yury@magic.io>2018-04-03 00:01:41 -0400
commit5804f0c47e60c7c2a0915cce2dbcfc7593881761 (patch)
treeb58320f6872c79ee88f6df31f9028a1707870b9b /immutables
parent451a84825d82e7fba4022857085ee2977f9a1d09 (diff)
downloadimmutables-5804f0c47e60c7c2a0915cce2dbcfc7593881761.tar.gz
immutables-5804f0c47e60c7c2a0915cce2dbcfc7593881761.zip
Change Map.delete(key): raise a KeyError if key is not in the map
Diffstat (limited to 'immutables')
-rw-r--r--immutables/_map.c4
-rw-r--r--immutables/map.py7
2 files changed, 5 insertions, 6 deletions
diff --git a/immutables/_map.c b/immutables/_map.c
index 445b713..3ed0393 100644
--- a/immutables/_map.c
+++ b/immutables/_map.c
@@ -2355,8 +2355,8 @@ map_without(MapObject *o, PyObject *key)
case W_EMPTY:
return map_new();
case W_NOT_FOUND:
- Py_INCREF(o);
- return o;
+ PyErr_SetObject(PyExc_KeyError, key);
+ return NULL;
case W_NEWNODE: {
assert(new_root != NULL);
diff --git a/immutables/map.py b/immutables/map.py
index ffed188..b6d55dc 100644
--- a/immutables/map.py
+++ b/immutables/map.py
@@ -126,7 +126,7 @@ class BitmapNode:
if key == key_or_null:
return val_or_node
- raise KeyError
+ raise KeyError(key)
def without(self, shift, hash, key):
bit = map_bitpos(hash, shift)
@@ -240,7 +240,7 @@ class CollisionNode:
for i in range(0, self.size, 2):
if self.array[i] == key:
return self.array[i + 1]
- raise KeyError
+ raise KeyError(key)
def assoc(self, shift, hash, key, val, added_leaf):
if hash == self.hash:
@@ -388,8 +388,7 @@ class Map:
if res is W_EMPTY:
return Map()
elif res is W_NOT_FOUND:
- # raise KeyError(key)
- return self
+ raise KeyError(key)
else:
m = Map.__new__(Map)
m.__count = self.__count - 1