[pypy-commit] pypy set-strategies: need to use StopItertion to check for last element in list

l.diekmann noreply at buildbot.pypy.org
Thu Nov 10 13:51:04 CET 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49195:fc1ddf33f169
Date: 2011-07-28 13:31 +0200
http://bitbucket.org/pypy/pypy/changeset/fc1ddf33f169/

Log:	need to use StopItertion to check for last element in list

diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -11,6 +11,7 @@
 from pypy.rlib.objectmodel import instantiate
 from pypy.interpreter.generator import GeneratorIterator
 from pypy.objspace.std.listobject import W_ListObject
+from pypy.objspace.std.intobject import W_IntObject
 
 class W_BaseSetObject(W_Object):
     typedef = None
@@ -208,7 +209,6 @@
         return clone
 
     def add(self, w_set, w_key):
-        from pypy.objspace.std.intobject import W_IntObject
         if type(w_key) is W_IntObject:
             w_set.strategy = self.space.fromcache(IntegerSetStrategy)
         else:
@@ -722,11 +722,13 @@
         return
 
     # check for integers
-    for item_w in w_iterable:
-        if type(item_w) is not W_IntObject:
-            break;
-        #XXX wont work for [1, "two", "three", 1] use StopIteration instead
-        if item_w is w_iterable[-1]:
+    iterator = iter(w_iterable)
+    while True:
+        try:
+            item_w = iterator.next()
+            if type(item_w) is not W_IntObject:
+                break;
+        except StopIteration:
             w_set.strategy = space.fromcache(IntegerSetStrategy)
             w_set.sstorage = w_set.strategy.get_storage_from_list(w_iterable)
             return


More information about the pypy-commit mailing list