[pypy-commit] pypy typed-cells: small cleanup

cfbolz noreply at buildbot.pypy.org
Fri Jan 23 10:42:11 CET 2015


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: typed-cells
Changeset: r75492:b44911a280e7
Date: 2015-01-23 00:00 +0100
http://bitbucket.org/pypy/pypy/changeset/b44911a280e7/

Log:	small cleanup

diff --git a/pypy/objspace/std/celldict.py b/pypy/objspace/std/celldict.py
--- a/pypy/objspace/std/celldict.py
+++ b/pypy/objspace/std/celldict.py
@@ -10,17 +10,13 @@
     DictStrategy, ObjectDictStrategy, _never_equal_to_string,
     create_iterator_classes)
 from pypy.objspace.std.typeobject import (
-    MutableCell, IntMutableCell, ObjectMutableCell, write_cell)
+    MutableCell, IntMutableCell, ObjectMutableCell, write_cell,
+    unwrap_cell)
 
 
 class VersionTag(object):
     pass
 
-def unwrap_cell(space, w_value):
-    if isinstance(w_value, MutableCell):
-        return w_value.unwrap_cell(space)
-    return w_value
-
 
 def _wrapkey(space, key):
     return space.wrap(key)
diff --git a/pypy/objspace/std/dictproxyobject.py b/pypy/objspace/std/dictproxyobject.py
--- a/pypy/objspace/std/dictproxyobject.py
+++ b/pypy/objspace/std/dictproxyobject.py
@@ -3,7 +3,7 @@
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.objspace.std.dictmultiobject import (
     DictStrategy, create_iterator_classes)
-from pypy.objspace.std.typeobject import unwrap_cell
+from pypy.objspace.std.typeobject import unwrap_cell_iftypeversion
 
 
 class DictProxyStrategy(DictStrategy):
@@ -83,11 +83,12 @@
         return space.newlist_bytes(self.unerase(w_dict.dstorage).dict_w.keys())
 
     def values(self, w_dict):
-        return [unwrap_cell(self.space, w_value) for w_value in self.unerase(w_dict.dstorage).dict_w.itervalues()]
+        return [unwrap_cell_iftypeversion(self.space, w_value)
+                    for w_value in self.unerase(w_dict.dstorage).dict_w.itervalues()]
 
     def items(self, w_dict):
         space = self.space
-        return [space.newtuple([space.wrap(key), unwrap_cell(self.space, w_value)])
+        return [space.newtuple([space.wrap(key), unwrap_cell_iftypeversion(self.space, w_value)])
                     for (key, w_value) in self.unerase(w_dict.dstorage).dict_w.iteritems()]
 
     def clear(self, w_dict):
@@ -108,6 +109,6 @@
     def wrapkey(space, key):
         return space.wrap(key)
     def wrapvalue(space, value):
-        return unwrap_cell(space, value)
+        return unwrap_cell_iftypeversion(space, value)
 
 create_iterator_classes(DictProxyStrategy)
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -36,11 +36,15 @@
     def __repr__(self):
         return "<IntMutableCell: %s>" % (self.intvalue, )
 
+def unwrap_cell(space, w_value):
+    if isinstance(w_value, MutableCell):
+        return w_value.unwrap_cell(space)
+    return w_value
 
-def unwrap_cell(space, w_value):
+
+def unwrap_cell_iftypeversion(space, w_value):
     if space.config.objspace.std.withtypeversion:
-        if isinstance(w_value, MutableCell):
-            return w_value.unwrap_cell(space)
+        return unwrap_cell(space, w_value)
     return w_value
 
 def write_cell(space, w_cell, w_value):
@@ -274,12 +278,12 @@
         if space.config.objspace.std.withtypeversion:
             version_tag = w_self.version_tag()
             if version_tag is not None:
-                return unwrap_cell(
+                return unwrap_cell_iftypeversion(
                     space,
                     w_self._pure_getdictvalue_no_unwrapping(
                         space, version_tag, attr))
         w_value = w_self._getdictvalue_no_unwrapping(space, attr)
-        return unwrap_cell(space, w_value)
+        return unwrap_cell_iftypeversion(space, w_value)
 
     def _getdictvalue_no_unwrapping(w_self, space, attr):
         w_value = w_self.dict_w.get(attr, None)


More information about the pypy-commit mailing list