[pypy-commit] pypy py3k: issue #1628: fix iter(iter(array.array()))

arigo noreply at buildbot.pypy.org
Fri Nov 1 14:57:51 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: py3k
Changeset: r67791:b6b883180ed9
Date: 2013-11-01 14:56 +0100
http://bitbucket.org/pypy/pypy/changeset/b6b883180ed9/

Log:	issue #1628: fix iter(iter(array.array()))

diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -645,6 +645,9 @@
     def __init__(self, array):
         self.index = 0
         self.array = array
+
+    def iter_w(self, space):
+        return space.wrap(self)
         
     def next_w(self, space):
         if self.index < self.array.len:
@@ -655,6 +658,7 @@
 
 ArrayIterator.typedef = TypeDef(
     'arrayiterator',
+    __iter__ = interp2app(ArrayIterator.iter_w),
     __next__ = interp2app(ArrayIterator.next_w),
     )
 
diff --git a/pypy/module/array/test/test_array.py b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -1154,3 +1154,9 @@
             b = array_reconstructor(
                 array.array, 'u', mformat_code, teststr.encode(encoding))
             assert a == b
+
+    def test_iterate_iterator(self):
+        import array
+        it = iter(array.array('b'))
+        assert list(it) == []
+        assert list(iter(it)) == []


More information about the pypy-commit mailing list