[pypy-svn] r75511 - in pypy/branch/fast-forward/pypy/objspace: . test

benjamin at codespeak.net benjamin at codespeak.net
Tue Jun 22 22:23:59 CEST 2010


Author: benjamin
Date: Tue Jun 22 22:23:58 2010
New Revision: 75511

Modified:
   pypy/branch/fast-forward/pypy/objspace/descroperation.py
   pypy/branch/fast-forward/pypy/objspace/test/test_descroperation.py
Log:
check an iterator for next in iter()

Modified: pypy/branch/fast-forward/pypy/objspace/descroperation.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/descroperation.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/descroperation.py	Tue Jun 22 22:23:58 2010
@@ -250,7 +250,12 @@
                                       "'%s' object is not iterable",
                                       typename)
             return space.newseqiter(w_obj)
-        return space.get_and_call_function(w_descr, w_obj)
+        w_iter = space.get_and_call_function(w_descr, w_obj)
+        w_next = space.lookup(w_iter, 'next')
+        if w_next is None:
+            raise OperationError(space.w_TypeError,
+                                 space.wrap("iter() returned non-iterator"))
+        return w_iter
 
     def next(space, w_obj):
         w_descr = space.lookup(w_obj, 'next')

Modified: pypy/branch/fast-forward/pypy/objspace/test/test_descroperation.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/test/test_descroperation.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/test/test_descroperation.py	Tue Jun 22 22:23:58 2010
@@ -457,6 +457,12 @@
         else:
             assert False, "did not raise"
 
+    def test_invalid_iterator(self):
+        class x(object):
+            def __iter__(self):
+                return self
+        raises(TypeError, iter, x())
+
 
 class AppTestWithBuiltinShortcut(AppTest_Descroperation):
     OPTIONS = {'objspace.std.builtinshortcut': True}



More information about the Pypy-commit mailing list