Author: Carl Friedrich Bolz <[email protected]>
Branch: share-mapdict-methods
Changeset: r84008:a1aab87118e0
Date: 2016-04-28 16:33 +0300
http://bitbucket.org/pypy/pypy/changeset/a1aab87118e0/

Log:    seems it's wrong to share deldictvalue, for somewhat involved
        reasons:

        there are classes that manage their own dict, and overwrite
        getdictvalue, setdictvalue, expecting to use the default
        implementation of deldictvalue. if you make a subclass of such a
        class, the shared mapdict base implementation would do the wrong
        thing.

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -49,8 +49,20 @@
             return True
         return False
 
-    # deldictvalue, getdict, setdict are mixed in from basemapdictobject
-    # def deldictvalue(self, space, attrname):
+    def deldictvalue(self, space, attrname):
+        from pypy.interpreter.error import OperationError
+        # check whether it has a dict and use that
+        w_dict = self.getdict(space)
+        if w_dict is not None:
+            try:
+                space.delitem(w_dict, space.wrap(attrname))
+                return True
+            except OperationError, ex:
+                if not ex.match(space, space.w_KeyError):
+                    raise
+        return False
+
+    # getdict, setdict are mixed in from basemapdictobject
     # def getdict(self, space):
     # def setdict(self, space, w_dict):
 
diff --git a/pypy/objspace/std/basemapdictobject.py 
b/pypy/objspace/std/basemapdictobject.py
--- a/pypy/objspace/std/basemapdictobject.py
+++ b/pypy/objspace/std/basemapdictobject.py
@@ -59,25 +59,6 @@
 
     # getdictvalue and setdictvalue are not done here, for performance reasons
 
-    def deldictvalue(self, space, attrname):
-        from pypy.interpreter.error import OperationError
-        map = self._get_mapdict_map()
-        if map is None:
-            # check whether it has a dict and use that
-            w_dict = self.getdict(space)
-            if w_dict is not None:
-                try:
-                    space.delitem(w_dict, space.wrap(attrname))
-                    return True
-                except OperationError, ex:
-                    if not ex.match(space, space.w_KeyError):
-                        raise
-            return False
-        new_obj = map.delete(self, attrname, DICT)
-        if new_obj is None:
-            return False
-        self._set_mapdict_storage_and_map(new_obj.storage, new_obj.map)
-        return True
 
     def getdict(self, space):
         from pypy.objspace.std.mapdict import MapDictStrategy
@@ -175,6 +156,7 @@
 
     def setweakref(self, space, weakreflifeline):
         from pypy.module._weakref.interp__weakref import WeakrefLifeline
+        from pypy.interpreter.error import oefmt
         map = self._get_mapdict_map()
         if map is None:
             # not a user-defined subclass
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -495,6 +495,14 @@
     def setdictvalue(self, space, attrname, w_value):
         return self._get_mapdict_map().write(self, attrname, DICT, w_value)
 
+    def deldictvalue(self, space, attrname):
+        map = self._get_mapdict_map()
+        new_obj = map.delete(self, attrname, DICT)
+        if new_obj is None:
+            return False
+        self._set_mapdict_storage_and_map(new_obj.storage, new_obj.map)
+        return True
+
 
 class MapdictStorageMixin(object):
     def _mapdict_init_empty(self, map):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to