[pypy-commit] pypy list-strategies: test_listobject works again: changed init method to call W_List.append instead of wrapped_items.append

l.diekmann noreply at buildbot.pypy.org
Fri Sep 23 13:11:13 CEST 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47415:0da72c36ed08
Date: 2011-02-01 14:37 +0100
http://bitbucket.org/pypy/pypy/changeset/0da72c36ed08/

Log:	test_listobject works again: changed init method to call
	W_List.append instead of wrapped_items.append

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -48,6 +48,9 @@
 
     def append(w_list, w_item):
         w_list.wrappeditems.append(w_item)
+        if isinstance(w_list.strategy, EmptyListStrategy):
+            w_list.strategy = ObjectListStrategy()
+            w_list.strategy.init_from_list_w(w_list, w_list.wrappeditems)
 
     # ___________________________________________________
 
@@ -148,7 +151,8 @@
                 if not e.match(space, space.w_StopIteration):
                     raise
                 break  # done
-            items_w.append(w_item)
+            #items_w.append(w_item)
+            w_list.append(w_item)
 
 def len__List(space, w_list):
     result = w_list.length()
@@ -429,7 +433,8 @@
     return space.w_None
 
 def list_append__List_ANY(space, w_list, w_any):
-    w_list.wrappeditems.append(w_any)
+    #w_list.wrappeditems.append(w_any)
+    w_list.append(w_any)
     return space.w_None
 
 def list_extend__List_List(space, w_list, w_other):
diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -5,4 +5,12 @@
 
     def test_check_strategy(self):
         assert isinstance(W_ListObject([]).strategy, EmptyListStrategy)
-        assert isinstance(W_ListObject([1]).strategy, ObjectListStrategy)
+        assert isinstance(W_ListObject([self.space.wrap(1),self.space.wrap('a')]).strategy, ObjectListStrategy)
+        assert isinstance(W_ListObject([self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)]).strategy, ObjectListStrategy)
+        assert isinstance(W_ListObject([self.space.wrap('a'), self.space.wrap('b')]).strategy, ObjectListStrategy)
+
+    def test_switch_strategy(self):
+        l = W_ListObject([])
+        assert isinstance(l.strategy, EmptyListStrategy)
+        l.append(self.space.wrap(1))
+        assert isinstance(l.strategy, ObjectListStrategy)


More information about the pypy-commit mailing list