[pypy-svn] rev 622 - in pypy/trunk/src/pypy/objspace/std: . test

tismer at codespeak.net tismer at codespeak.net
Wed May 28 16:08:33 CEST 2003


Author: tismer
Date: Wed May 28 16:08:33 2003
New Revision: 622

Modified:
   pypy/trunk/src/pypy/objspace/std/listobject.py
   pypy/trunk/src/pypy/objspace/std/test/test_listobject.py
   pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py
   pypy/trunk/src/pypy/objspace/std/tupleobject.py
Log:
added left multiply to ints and tuples, with test working

Modified: pypy/trunk/src/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/listobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/listobject.py	Wed May 28 16:08:33 2003
@@ -85,6 +85,11 @@
 
 StdObjSpace.mul.register(list_int_mul, W_ListObject, W_IntObject)
 
+def int_list_mul(space, w_int, w_list):
+    return list_int_mul(space, w_list, w_int)
+
+StdObjSpace.mul.register(int_list_mul, W_IntObject, W_ListObject)
+
 def list_eq(space, w_list1, w_list2):
     items1 = w_list1.wrappeditems
     items2 = w_list2.wrappeditems
@@ -111,6 +116,23 @@
 
 StdObjSpace.setitem.register(setitem_list_int, W_ListObject, W_IntObject, W_ANY)
 
+# not trivial!
+def setitem_list_slice(space, w_list, w_slice, w_list2):
+    items = w_list.wrappeditems
+    w_length = space.wrap(len(items))
+    w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length)
+    start       = space.unwrap(w_start)
+    step        = space.unwrap(w_step)
+    slicelength = space.unwrap(w_slicelength)
+    assert slicelength >= 0
+    subitems = [None] * slicelength
+    for i in range(slicelength):
+        subitems[i] = items[start]
+        start += step
+    return W_ListObject(space, subitems)
+
+StdObjSpace.setitem.register(setitem_list_slice, W_ListObject, W_SliceObject, W_ANY)
+
 def getattr_list(space, w_list, w_attr):
     if space.is_true(space.eq(w_attr, space.wrap('append'))):
         w_builtinfn = make_builtin_func(space, W_ListObject.append)

Modified: pypy/trunk/src/pypy/objspace/std/test/test_listobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_listobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_listobject.py	Wed May 28 16:08:33 2003
@@ -41,6 +41,9 @@
         w_lis3 = lobj.W_ListObject(self.space, [arg]*n)
         w_res = self.space.mul(w_lis, w(n))
         self.assertEqual_w(w_lis3, w_res)
+        # commute
+        w_res = self.space.mul(w(n), w_lis)
+        self.assertEqual_w(w_lis3, w_res)
 
     def test_getitem(self):
         w = self.space.wrap

Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py	Wed May 28 16:08:33 2003
@@ -91,6 +91,9 @@
         w_tup3 = tobj.W_TupleObject(self.space, [arg]*n)
         w_res = self.space.mul(w_tup, w(n))
         self.assertEqual_w(w_tup3, w_res)
+        # commute
+        w_res = self.space.mul(w(n), w_tup)
+        self.assertEqual_w(w_tup3, w_res)
 
     def test_getslice(self):
         w = self.space.wrap

Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/tupleobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/tupleobject.py	Wed May 28 16:08:33 2003
@@ -79,6 +79,11 @@
 
 StdObjSpace.mul.register(tuple_int_mul, W_TupleObject, W_IntObject)
 
+def int_tuple_mul(space, w_int, w_tuple):
+    return tuple_int_mul(space, w_tuple, w_int)
+
+StdObjSpace.mul.register(int_tuple_mul, W_IntObject, W_TupleObject)
+
 def tuple_eq(space, w_tuple1, w_tuple2):
     items1 = w_tuple1.wrappeditems
     items2 = w_tuple2.wrappeditems


More information about the Pypy-commit mailing list