[pypy-commit] pypy list-strategies: Choose ListStrategy matching items in list

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


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47414:58cd6e224558
Date: 2011-02-01 13:07 +0100
http://bitbucket.org/pypy/pypy/changeset/58cd6e224558/

Log:	Choose ListStrategy matching items in list (had to change .hgsub to
	do commits - otherwise got error: unknown subrepo source)

diff --git a/.hgsub b/.hgsub
--- a/.hgsub
+++ b/.hgsub
@@ -1,4 +1,4 @@
-greenlet = [svn]http://codespeak.net/svn/greenlet/trunk/c
-testrunner = [svn]http://codespeak.net/svn/pypy/build/testrunner
-lib_pypy/pyrepl = [svn]http://codespeak.net/svn/pyrepl/trunk/pyrepl/pyrepl
-lib_pypy/sqlite3 = [svn]http://codespeak.net/svn/pypy/pysqlite2
+#greenlet = [svn]http://codespeak.net/svn/greenlet/trunk/c
+#testrunner = [svn]http://codespeak.net/svn/pypy/build/testrunner
+#lib_pypy/pyrepl = [svn]http://codespeak.net/svn/pyrepl/trunk/pyrepl/pyrepl
+#lib_pypy/sqlite3 = [svn]http://codespeak.net/svn/pypy/pysqlite2
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
@@ -22,12 +22,18 @@
     assert wrapper._from_where == from_where
     return wrapper._content
 
+# don't know where to put this function, so it is global for now
+def get_strategy_from_list_objects(list_w):
+    if list_w == []:
+        return EmptyListStrategy()
+    return ObjectListStrategy()
+
 class W_ListObject(W_Object):
     from pypy.objspace.std.listtype import list_typedef as typedef
 
     def __init__(w_self, wrappeditems):
         assert isinstance(wrappeditems, list)
-        w_self.strategy = ObjectListStrategy()
+        w_self.strategy = get_strategy_from_list_objects(wrappeditems)
         w_self.strategy.init_from_list_w(w_self, wrappeditems)
         w_self.wrappeditems = wrappeditems
 
diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
new file mode 100644
--- /dev/null
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -0,0 +1,8 @@
+from pypy.objspace.std.listobject import W_ListObject, EmptyListStrategy, ObjectListStrategy
+from pypy.objspace.std.test.test_listobject import TestW_ListObject
+
+class TestW_ListStrategies(TestW_ListObject):
+
+    def test_check_strategy(self):
+        assert isinstance(W_ListObject([]).strategy, EmptyListStrategy)
+        assert isinstance(W_ListObject([1]).strategy, ObjectListStrategy)


More information about the pypy-commit mailing list