[pypy-svn] r76697 - in pypy/branch/better-map-instances/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Aug 21 12:04:04 CEST 2010


Author: cfbolz
Date: Sat Aug 21 12:04:03 2010
New Revision: 76697

Modified:
   pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py
   pypy/branch/better-map-instances/pypy/objspace/std/test/test_dictmultiobject.py
   pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py
Log:
fix deletion in devolved dicts


Modified: pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py	(original)
+++ pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py	Sat Aug 21 12:04:03 2010
@@ -1,5 +1,3 @@
-
-
 # ____________________________________________________________
 # attribute shapes
 
@@ -16,6 +14,9 @@
         raise NotImplementedError("abstract base class")
 
     def delete(self, obj, selector):
+        return None
+
+    def copy(self, obj):
         raise NotImplementedError("abstract base class")
 
     def length(self):
@@ -67,7 +68,7 @@
         obj.map.add_attr(obj, selector, w_value)
         return True
 
-    def delete(self, obj, selector):
+    def copy(self, obj):
         result = Object()
         result._init_empty(self)
         return result
@@ -117,14 +118,16 @@
         Terminator.write(self, obj, selector, w_value)
 
     def delete(self, obj, selector):
+        from pypy.interpreter.error import OperationError
         if selector[1] == DICT:
             w_dict = obj.getdict()
             space = obj.space # XXX
             try:
-                space.delitem(w_dict, w_name)
+                space.delitem(w_dict, space.wrap(selector[0]))
             except OperationError, ex:
                 if not ex.match(space, space.w_KeyError):
                     raise
+            return Terminator.copy(self, obj)
         return Terminator.delete(self, obj, selector)
 
 
@@ -151,11 +154,19 @@
         return self.back.write(obj, selector, w_value)
 
     def delete(self, obj, selector):
+        if self.selector == selector:
+            # ok, attribute is deleted
+            return self.back.copy(obj)
         new_obj = self.back.delete(obj, selector)
-        if self.selector != selector:
+        if new_obj is not None:
             self._copy_attr(obj, new_obj)
         return new_obj
 
+    def copy(self, obj):
+        new_obj = self.back.copy(obj)
+        self._copy_attr(obj, new_obj)
+        return new_obj
+
     def length(self):
         return self.position + 1
 
@@ -209,8 +220,7 @@
     def deldictvalue(self, space, w_name):
         attrname = space.str_w(w_name)
         new_obj = self.map.delete(self, (attrname, DICT))
-        # XXX too slow? XXX wrong for devolved dicts
-        if new_obj.map is self.map and new_obj.storage == self.storage:
+        if new_obj is None:
             return False
         self._become(new_obj)
         return True

Modified: pypy/branch/better-map-instances/pypy/objspace/std/test/test_dictmultiobject.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/objspace/std/test/test_dictmultiobject.py	(original)
+++ pypy/branch/better-map-instances/pypy/objspace/std/test/test_dictmultiobject.py	Sat Aug 21 12:04:03 2010
@@ -608,6 +608,9 @@
     def setitem_str(self, w_dict, s, w_value):
         return w_dict.setitem_str(s, w_value) # assume it's a multidict
 
+    def delitem(self, w_dict, w_s):
+        return w_dict.delitem(w_s) # assume it's a multidict
+
     def allocate_instance(self, cls, type):
         return object.__new__(cls)
 

Modified: pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py	(original)
+++ pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py	Sat Aug 21 12:04:03 2010
@@ -309,4 +309,6 @@
     assert obj.getslotvalue(a) == 501
     assert obj.getslotvalue(b) == 601
     assert obj.getslotvalue(c) == 701
-
+    res = obj.deldictvalue(space, "a")
+    assert res
+    assert obj.getdictvalue(space, "a") is None



More information about the Pypy-commit mailing list