Author: Lukas Diekmann <[email protected]>
Branch: list-strategies
Changeset: r47516:88a3af314c60
Date: 2011-07-15 11:31 +0200
http://bitbucket.org/pypy/pypy/changeset/88a3af314c60/

Log:    fixed getstrategyfromlist_w method: e is l[-1] is also true for some
        equal first and last elements (1, True)

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
@@ -27,17 +27,23 @@
         return space.fromcache(EmptyListStrategy)
 
     # check for ints
-    for e in list_w:
-        if not is_W_IntObject(e):
-            break
-        if e is list_w[-1]:
+    it = iter(list_w)
+    while(True):
+        try:
+            e = it.next()
+            if not is_W_IntObject(e):
+                break
+        except StopIteration:
             return space.fromcache(IntegerListStrategy)
 
-    # check for ints
-    for e in list_w:
-        if not is_W_StringObject(e):
-            break
-        if e is list_w[-1]:
+    # check for strings
+    it = iter(list_w)
+    while(True):
+        try:
+            e = it.next()
+            if not is_W_StringObject(e):
+                break
+        except StopIteration:
             return space.fromcache(StringListStrategy)
 
     return space.fromcache(ObjectListStrategy)
@@ -1177,6 +1183,7 @@
             sorterclass = CustomKeySort
         else:
             sorterclass = SimpleSort
+    #XXX optimize this, getitems is bad
     sorter = sorterclass(w_list.getitems(), w_list.length())
     sorter.space = space
     sorter.w_cmp = w_cmp
diff --git a/pypy/objspace/std/test/test_listobject.py 
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -343,6 +343,15 @@
 
 
 class AppTestW_ListObject(object):
+
+    def test_getstrategyfromlist_w(self):
+        l0 = ["a", "2", "a", True]
+
+        # this raised TypeError on ListStrategies
+        l1 = ["a", "2", True, "a"]
+        l2 = [1, "2", "a", "a"]
+        assert sorted(l1) == sorted(l2)
+
     def test_call_list(self):
         assert list('') == []
         assert list('abc') == ['a', 'b', 'c']
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to