[pypy-commit] pypy list-strategies: Switch strategy depending on type of item that was set

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


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47422:3a9a1a59af86
Date: 2011-02-16 12:51 +0100
http://bitbucket.org/pypy/pypy/changeset/3a9a1a59af86/

Log:	Switch strategy depending on type of item that was set

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
@@ -251,6 +251,10 @@
         list_w = cast_from_void_star(w_list.storage, "integer")
         list_w[index] = w_item
 
+        if not is_W_IntObject(w_item):
+            w_list.strategy = ObjectListStrategy()
+            w_list.strategy.init_from_list_w(w_list, list_w)
+
 class StringListStrategy(ListStrategy):
 
     def init_from_list_w(self, w_list, list_w):
@@ -298,6 +302,10 @@
         list_w = cast_from_void_star(w_list.storage, "string")
         list_w[index] = w_item
 
+        if not is_W_StringObject(w_item):
+            w_list.strategy = ObjectListStrategy()
+            w_list.strategy.init_from_list_w(w_list, list_w)
+
 # _______________________________________________________
 
 init_signature = Signature(['sequence'], None, None)
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
@@ -48,10 +48,17 @@
         l.setitem(0, self.space.wrap('d'))
         assert self.space.eq_w(l.getitem(0), self.space.wrap('d'))
 
-        # Test strategy change
+        assert isinstance(l.strategy, StringListStrategy)
+
+        # IntStrategy to ObjectStrategy
         l = W_ListObject([self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)])
         assert isinstance(l.strategy, IntegerListStrategy)
         l.setitem(0, self.space.wrap('d'))
         assert isinstance(l.strategy, ObjectListStrategy)
 
+        # StringStrategy to ObjectStrategy
+        l = W_ListObject([self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')])
+        assert isinstance(l.strategy, StringListStrategy)
+        l.setitem(0, self.space.wrap(2))
+        assert isinstance(l.strategy, ObjectListStrategy)
 


More information about the pypy-commit mailing list