Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r75429:4f5f684ab5f9
Date: 2015-01-18 23:02 +0100
http://bitbucket.org/pypy/pypy/changeset/4f5f684ab5f9/

Log:    Minimal fixes so that a _stm.hashtable at least feels like a dict,
        even if it has no way to enumerate the keys

diff --git a/pypy/module/_stm/hashtable.py b/pypy/module/_stm/hashtable.py
--- a/pypy/module/_stm/hashtable.py
+++ b/pypy/module/_stm/hashtable.py
@@ -29,9 +29,17 @@
         self.h.set(key, gcref)
 
     @unwrap_spec(key=int)
-    def delitem_w(self, key):
+    def delitem_w(self, space, key):
+        gcref = self.h.get(key)
+        if not gcref:
+            space.raise_key_error(space.wrap(key))
         self.h.set(key, rstm.NULL_GCREF)
 
+    @unwrap_spec(key=int)
+    def contains_w(self, space, key):
+        gcref = self.h.get(key)
+        return space.newbool(not not gcref)
+
 
 def W_Hashtable___new__(space, w_subtype):
     r = space.allocate_instance(W_Hashtable, w_subtype)
@@ -44,4 +52,5 @@
     __getitem__ = interp2app(W_Hashtable.getitem_w),
     __setitem__ = interp2app(W_Hashtable.setitem_w),
     __delitem__ = interp2app(W_Hashtable.delitem_w),
+    __contains__ = interp2app(W_Hashtable.contains_w),
     )
diff --git a/pypy/module/_stm/test/test_hashtable.py 
b/pypy/module/_stm/test/test_hashtable.py
--- a/pypy/module/_stm/test/test_hashtable.py
+++ b/pypy/module/_stm/test/test_hashtable.py
@@ -10,6 +10,9 @@
         raises(KeyError, "h[42]")
         h[42] = "foo"
         assert h[42] == "foo"
+        assert 42 in h
         del h[42]
+        assert 42 not in h
         raises(KeyError, "h[42]")
         assert h[42+65536] == "bar"
+        raises(KeyError, "del h[42]")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to