[pypy-svn] r34096 - in pypy/branch/transparent-proxy/pypy/objspace/std: . test

fijal at codespeak.net fijal at codespeak.net
Fri Nov 3 13:44:10 CET 2006


Author: fijal
Date: Fri Nov  3 13:44:07 2006
New Revision: 34096

Modified:
   pypy/branch/transparent-proxy/pypy/objspace/std/listobject.py
   pypy/branch/transparent-proxy/pypy/objspace/std/model.py
   pypy/branch/transparent-proxy/pypy/objspace/std/objspace.py
   pypy/branch/transparent-proxy/pypy/objspace/std/proxy_helpers.py
   pypy/branch/transparent-proxy/pypy/objspace/std/stdtypedef.py
   pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py
Log:
(pedronis, fijal) - Fix the list implementation by having AnyList (and AnyXxx as well) for implementing different multimethods.


Modified: pypy/branch/transparent-proxy/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/listobject.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/listobject.py	Fri Nov  3 13:44:07 2006
@@ -78,12 +78,15 @@
 def add__List_List(space, w_list1, w_list2):
     return W_ListObject(w_list1.wrappeditems + w_list2.wrappeditems)
 
-def add__List_ANY(space, w_list, w_any):
-    if space.is_true(space.isinstance(w_any, space.w_list)):
-        items1_w = w_list.wrappeditems
-        items2_w = space.unpackiterable(w_any)
-        return W_ListObject(items1_w + items2_w)
-    raise FailedToImplement
+#def radd__List_List(space, w_list1, w_list2):
+#    return W_ListObject(w_list2.wrappeditems + w_list1.wrappeditems)
+
+##def add__List_ANY(space, w_list, w_any):
+##    if space.is_true(space.isinstance(w_any, space.w_list)):
+##        items1_w = w_list.wrappeditems
+##        items2_w = space.unpackiterable(w_any)
+##        return W_ListObject(items1_w + items2_w)
+##    raise FailedToImplement
 
 def inplace_add__List_ANY(space, w_list1, w_iterable2):
     list_extend__List_ANY(space, w_list1, w_iterable2)
@@ -131,12 +134,12 @@
     return space.w_True
     #return space.newbool(len(w_list1.wrappeditems) == len(w_list2.wrappeditems))
 
-def eq__List_ANY(space, w_list1, w_any):
-    if space.is_true(space.isinstance(w_any, space.w_list)):
-        items1_w = w_list1.wrappeditems
-        items2_w = space.unpackiterable(w_any)
-        return equal_wrappeditems(space, items1_w, items2_w)
-    raise FailedToImplement
+##def eq__List_ANY(space, w_list1, w_any):
+##    if space.is_true(space.isinstance(w_any, space.w_list)):
+##        items1_w = w_list1.wrappeditems
+##        items2_w = space.unpackiterable(w_any)
+##        return equal_wrappeditems(space, items1_w, items2_w)
+##    raise FailedToImplement
 
 def _min(a, b):
     if a < b:
@@ -173,25 +176,25 @@
     return lessthan_unwrappeditems(space, w_list1.wrappeditems,
         w_list2.wrappeditems)
 
-def lt__List_ANY(space, w_list1, w_any):
-    # XXX: Implement it not unpacking all the elements
-    if space.is_true(space.isinstance(w_any, space.w_list)):
-        items1_w = w_list1.wrappeditems
-        items2_w = space.unpackiterable(w_any)
-        return lessthan_unwrappeditems(space, items1_w, items2_w)
-    raise FailedToImplement
+##def lt__List_ANY(space, w_list1, w_any):
+##    # XXX: Implement it not unpacking all the elements
+##    if space.is_true(space.isinstance(w_any, space.w_list)):
+##        items1_w = w_list1.wrappeditems
+##        items2_w = space.unpackiterable(w_any)
+##        return lessthan_unwrappeditems(space, items1_w, items2_w)
+##    raise FailedToImplement
 
 def gt__List_List(space, w_list1, w_list2):
     return greaterthan_unwrappeditems(space, w_list1.wrappeditems,
         w_list2.wrappeditems)
 
-def gt__List_ANY(space, w_list1, w_any):
-    # XXX: Implement it not unpacking all the elements
-    if space.is_true(space.isinstance(w_any, space.w_list)):
-        items1_w = w_list1.wrappeditems
-        items2_w = space.unpackiterable(w_any)
-        return greaterthan_unwrappeditems(space, items1_w, items2_w)
-    raise FailedToImplement
+##def gt__List_ANY(space, w_list1, w_any):
+##    # XXX: Implement it not unpacking all the elements
+##    if space.is_true(space.isinstance(w_any, space.w_list)):
+##        items1_w = w_list1.wrappeditems
+##        items2_w = space.unpackiterable(w_any)
+##        return greaterthan_unwrappeditems(space, items1_w, items2_w)
+##    raise FailedToImplement
 
 def delitem__List_ANY(space, w_list, w_idx):
     idx = space.int_w(w_idx)

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/model.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/model.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/model.py	Fri Nov  3 13:44:07 2006
@@ -201,6 +201,9 @@
         # put W_Root everywhere
         self.typeorder[W_Root] = []
         for type in self.typeorder:
+            from pypy.objspace.std import stdtypedef
+            if type is not W_Root and isinstance(type.typedef, stdtypedef.StdTypeDef):
+                self.typeorder[type].append((type.typedef.any, None))
             self.typeorder[type].append((W_Root, None))
 
         # ____________________________________________________________

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/objspace.py	Fri Nov  3 13:44:07 2006
@@ -554,7 +554,7 @@
         w_start = space.add(w_start, space.len(w_obj))
         # NB. the language ref is inconsistent with the new-style class
         # behavior when w_obj doesn't implement __len__(), so we just
-        # ignore this case.
+        # ignore this case.eq
     if space.is_w(w_stop, space.w_None):
         w_stop = space.wrap(slice_max)
     elif space.is_true(space.lt(w_stop, space.wrap(0))):

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/proxy_helpers.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/proxy_helpers.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/proxy_helpers.py	Fri Nov  3 13:44:07 2006
@@ -3,7 +3,8 @@
 of cyclic imports
 """
 
-from pypy.objspace.std.model import W_ANY
+from pypy.objspace.std.model import W_ANY, W_Object
+from pypy.interpreter import baseobjspace
 
 def create_mm_names(classname, mm, is_local):
     s = ""
@@ -18,15 +19,47 @@
 def install_mm_trampoline(type_, mm, is_local):
     classname = type_.__name__[2:]
     mm_name, op_name = create_mm_names(classname, mm, is_local)
+    # we search here for special-cased stuff
     def function(space, w_transparent_list, *args_w):
         return space.call_function(w_transparent_list.controller, space.wrap\
             (op_name), *args_w)
     function.func_name = mm_name
     mm.register(function, type_, *([W_ANY] * (mm.arity - 1)))
 
+def is_special_doublearg(mm, type_):
+    """ We specialcase when we've got two argument method for which
+    there exist reverse operation
+    """
+    if mm.arity != 2:
+        return False
+    
+    if len(mm.specialnames) != 2:
+        return False
+    
+    # search over the signatures
+    for signature in mm.signatures():
+        if signature == (type_.original, type_.original):
+            return True
+    return False
+
+def install_mm_special(type_, mm, is_local):
+    classname = type_.__name__[2:]
+    #mm_name, op_name = create_mm_names(classname, mm, is_local)
+    
+    def function(space, w_any, w_transparent_list):
+        retval = space.call_function(w_transparent_list.controller, space.wrap(mm.specialnames[1]),
+            w_any)
+        return retval
+        
+    function.func_name = mm.specialnames[0]
+    
+    mm.register(function, type_.typedef.any, type_)
+
 def register_type(type_):
     from pypy.objspace.std.stdtypedef import multimethods_defined_on
     
     for mm, is_local in multimethods_defined_on(type_.original):
         if not mm.name.startswith('__'):
             install_mm_trampoline(type_, mm, is_local)
+            if is_special_doublearg(mm, type_):
+                install_mm_special(type_, mm, is_local)

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/stdtypedef.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/stdtypedef.py	Fri Nov  3 13:44:07 2006
@@ -20,6 +20,7 @@
     def __init__(self, __name, __base=None, **rawdict):
         "NOT_RPYTHON: initialization-time only."
         TypeDef.__init__(self, __name, __base, **rawdict)
+        self.any = type("W_Any"+__name.title(), (baseobjspace.W_Root,), {'typedef': self})
         self.local_multimethods = []
 
     def registermethods(self, namespace):

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py	Fri Nov  3 13:44:07 2006
@@ -35,15 +35,14 @@
         assert repr(lst) == repr([1,2])
 
     def test_gt_lt_list(self):
-        skip("FAILS RANDOMLY (~73% works)")
         c = self.Controller([])
         lst = proxy(list, c.perform)
         lst.append(1)
         lst.append(2)
-        #assert lst < [1,2,3]
-        #assert [1,2,3] > lst
-        #assert lst == [1,2]
-        #assert [1,2] == lst
+        assert lst < [1,2,3]
+        assert [1,2,3] > lst
+        assert lst == [1,2]
+        assert [1,2] == lst
         assert [2,3] >= list(iter(lst))
         assert lst < [2,3]
         assert [2,3] >= lst
@@ -54,6 +53,8 @@
         lst = proxy(list, c.perform)
         lst.append(1)
         assert lst + lst == [1,1]
+        assert lst + [1] == [1,1]
+        assert [1] + lst == [1,1]
 
     def test_list_getitem(self):
         c = self.Controller([1,2,3])



More information about the Pypy-commit mailing list