[pypy-svn] r68754 - in pypy/branch/shrink-multidict/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Oct 26 15:43:39 CET 2009


Author: cfbolz
Date: Mon Oct 26 15:43:38 2009
New Revision: 68754

Modified:
   pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py
   pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py
   pypy/branch/shrink-multidict/pypy/objspace/std/test/test_dictmultiobject.py
   pypy/branch/shrink-multidict/pypy/objspace/std/typeobject.py
Log:
A number of fixes.


Modified: pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py	Mon Oct 26 15:43:38 2009
@@ -133,7 +133,7 @@
     def next_entry(self):
         # note that this 'for' loop only runs once, at most
         for key, cell in self.iterator:
-            return (key, cell.w_value)
+            return (self.space.wrap(key), cell.w_value)
         else:
             return None, None
 

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py	Mon Oct 26 15:43:38 2009
@@ -110,15 +110,12 @@
         raise NotImplementedError("abstract base class")
 
     def impl_setitem_str(self,  w_key, w_value, shadows_type=True):
-        #return implementation
         raise NotImplementedError("abstract base class")
 
     def impl_setitem(self,  w_key, w_value):
-        #return implementation
         raise NotImplementedError("abstract base class")
 
     def impl_delitem(self, w_key):
-        #return implementation
         raise NotImplementedError("abstract base class")
  
     def impl_length(self):
@@ -127,6 +124,9 @@
     def impl_iter(self):
         raise NotImplementedError("abstract base class")
 
+    def impl_clear(self):
+        raise NotImplementedError("abstract base class")
+
     def impl_keys(self):
         iterator = self.impl_iter()
         result = []
@@ -150,7 +150,7 @@
         result = []
         while 1:
             w_key, w_value = iterator.next()
-            if w_item is not None:
+            if w_key is not None:
                 result.append(self.space.newtuple([w_key, w_value]))
             else:
                 return result
@@ -160,7 +160,7 @@
     # by the annotator
     def impl_get_builtin_indexed(self, i):
         w_key = self.space.wrap(OPTIMIZED_BUILTINS[i])
-        return self.getitem(w_key)
+        return self.impl_getitem(w_key)
 
     # this method will only be seen whan a certain config option is used
     def impl_shadows_anything(self):
@@ -197,40 +197,55 @@
     def impl_fallback_items(self):
         return [self.space.newtuple([w_key, w_val])
                     for w_key, w_val in self.r_dict_content.iteritems()]
+
     def impl_fallback_clear(self):
         self.r_dict_content.clear()
 
+    def impl_fallback_get_builtin_indexed(self, i):
+        w_key = self.space.wrap(OPTIMIZED_BUILTINS[i])
+        return self.impl_fallback_getitem(w_key)
+
+    def impl_fallback_shadows_anything(self):
+        return True
+
+    def impl_fallback_set_shadows_anything(self):
+        pass
+
+
 implementation_methods = [
-    "getitem",
-    "length",
-    "setitem_str",
-    "setitem",
-    "delitem",
-    "iter",
-    "items",
-    "values",
-    "keys",
-    "clear",
-    "get_builtin_indexed",
-    "shadows_anything",
-    "set_shadows_anything",
+    ("getitem", 1),
+    ("length", 0),
+    ("setitem_str", 3),
+    ("setitem", 2),
+    ("delitem", 1),
+    ("iter", 0),
+    ("items", 0),
+    ("values", 0),
+    ("keys", 0),
+    ("clear", 0),
+    ("get_builtin_indexed", 1),
+    ("shadows_anything", 0),
+    ("set_shadows_anything", 0),
 ]
 
 
-def _make_method(name, fallback):
-    def implementation_method(self, *args):
+def _make_method(name, implname, fallback, numargs):
+    args = ", ".join(["a" + str(i) for i in range(numargs)])
+    code = """def %s(self, %s):
         if self.r_dict_content is not None:
-            if not hasattr(self, fallback):
-                return getattr(W_DictMultiObject, name)(self, *args)
-            return getattr(self, fallback)(*args)
-        return getattr(self, name)(*args)
+            return self.%s(%s)
+        return self.%s(%s)""" % (name, args, fallback, args, implname, args)
+    d = {}
+    exec py.code.Source(code).compile() in d
+    implementation_method = d[name]
+    implementation_method.func_defaults = getattr(W_DictMultiObject, implname).func_defaults
     return implementation_method
 
 def _install_methods():
-    for name in implementation_methods:
+    for name, numargs in implementation_methods:
         implname = "impl_" + name
         fallbackname = "impl_fallback_" + name
-        func = _make_method(implname, fallbackname)
+        func = _make_method(name, implname, fallbackname, numargs)
         setattr(W_DictMultiObject, name, func)
 _install_methods()
 
@@ -354,8 +369,8 @@
 
     def next_entry(self):
         # note that this 'for' loop only runs once, at most
-        for item in self.iterator:
-            return item
+        for str, w_value in self.iterator:
+            return self.space.wrap(str), w_value
         else:
             return None, None
 
@@ -373,7 +388,7 @@
     def impl_setitem_str(self, w_key, w_value, shadows_type=True):
         if shadows_type:
             self._shadows_anything = True
-        StrDictImplementation.setitem_str(
+        StrDictImplementation.impl_setitem_str(
             self, w_key, w_value, shadows_type)
 
     def impl_setitem(self, w_key, w_value):
@@ -383,7 +398,7 @@
                 w_obj = self.w_type.lookup(space.str_w(w_key))
                 if w_obj is not None:
                     self._shadows_anything = True
-            StrDictImplementation.setitem_str(
+            StrDictImplementation.impl_setitem_str(
                 self, w_key, w_value, False)
         else:
             self._as_rdict().setitem(w_key, w_value)

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/test/test_dictmultiobject.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/test/test_dictmultiobject.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/test/test_dictmultiobject.py	Mon Oct 26 15:43:38 2009
@@ -603,6 +603,7 @@
     StringObjectCls = None  # xxx untested: shortcut in StrDictImpl.getitem
     w_dict = None
     iter = iter
+    viewiterable = list
 
 
 class Config:

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/typeobject.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/typeobject.py	Mon Oct 26 15:43:38 2009
@@ -281,8 +281,7 @@
         if w_self.lazyloaders:
             w_self._freeze_()    # force un-lazification
         space = w_self.space
-        newdic = space.newdict()
-        newdic.initialize_from_strdict_shared(w_self.dict_w)
+        newdic = space.newdict(from_strdict_shared=w_self.dict_w)
         return W_DictProxyObject(newdic)
 
     def unwrap(w_self, space):



More information about the Pypy-commit mailing list