[pypy-svn] r10081 - in pypy/dist/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Tue Mar 22 19:49:57 CET 2005


Author: arigo
Date: Tue Mar 22 19:49:56 2005
New Revision: 10081

Modified:
   pypy/dist/pypy/objspace/std/listobject.py
   pypy/dist/pypy/objspace/std/test/test_listobject.py
Log:
list '*=' operator was missing! argh.



Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py	(original)
+++ pypy/dist/pypy/objspace/std/listobject.py	Tue Mar 22 19:49:56 2005
@@ -34,6 +34,10 @@
         items = [space.unwrap(w_item) for w_item in w_list.ob_item[:w_list.ob_size]]# XXX generic mixed types unwrap
         return list(items)
 
+    def clear(w_list):
+        w_list.ob_item = []
+        w_list.ob_size = 0
+
 
 registerimplementation(W_ListObject)
 
@@ -42,7 +46,7 @@
     w_iterable, = __args__.parse('list',
                                (['sequence'], None, None),   # signature
                                [W_ListObject(space, [])])    # default argument
-    w_list.ob_size = 0  # XXX think about it later
+    w_list.clear()
 	
     length = 0
     try:
@@ -145,6 +149,23 @@
 def mul__ANY_List(space, w_times, w_list):
     return mul_list_times(space, w_list, space.int_w(w_times))
 
+def inplace_mul__List_ANY(space, w_list, w_times):
+    times = space.int_w(w_times)
+    if times <= 0:
+        w_list.clear()
+        return w_list
+    size = w_list.ob_size
+    newlen = size * times  # XXX check overflow
+    _list_resize(w_list, newlen)
+    items = w_list.ob_item
+    p = size
+    for _ in range(1, times):
+        for i in range(size):
+            items[p] = items[i]
+            p += 1
+    w_list.ob_size = newlen
+    return w_list
+
 def eq__List_List(space, w_list1, w_list2):
     items1 = w_list1.ob_item
     items2 = w_list2.ob_item

Modified: pypy/dist/pypy/objspace/std/test/test_listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_listobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_listobject.py	Tue Mar 22 19:49:56 2005
@@ -366,6 +366,19 @@
         assert l is l0
         assert l == [1,2,3,4,5]
 
+    def test_imul(self):
+        l = l0 = [4,3]
+        l *= 2
+        assert l is l0
+        assert l == [4,3,4,3]
+        l *= 0
+        assert l is l0
+        assert l == []
+        l = l0 = [4,3]
+        l *= (-1)
+        assert l is l0
+        assert l == []
+
     def test_index(self):
         l = ['a', 'b', 'c', 'd', 'e', 'f']
         raises(TypeError, l.index, 'c', 0, 4.3)



More information about the Pypy-commit mailing list