[pypy-commit] pypy length-hint: enable xrange iter's __length_hint__

pjenvey noreply at buildbot.pypy.org
Thu Sep 13 22:08:34 CEST 2012


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: length-hint
Changeset: r57329:ea7a1469385e
Date: 2012-09-13 13:07 -0700
http://bitbucket.org/pypy/pypy/changeset/ea7a1469385e/

Log:	enable xrange iter's __length_hint__

diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -422,7 +422,7 @@
         raise OperationError(self.space.w_StopIteration, self.space.w_None)
 
     def descr_len(self):
-        return self.space.wrap(self.remaining)
+        return self.space.wrap(self.get_remaining())
 
     def descr_reduce(self):
         from pypy.interpreter.mixedmodule import MixedModule
@@ -441,8 +441,7 @@
 
 W_XRangeIterator.typedef = TypeDef("rangeiterator",
     __iter__        = interp2app(W_XRangeIterator.descr_iter),
-# XXX __length_hint__()
-##    __len__         = interp2app(W_XRangeIterator.descr_len),
+    __length_hint__ = interp2app(W_XRangeIterator.descr_len),
     next            = interp2app(W_XRangeIterator.descr_next),
     __reduce__      = interp2app(W_XRangeIterator.descr_reduce),
 )
diff --git a/pypy/objspace/std/test/test_lengthhint.py b/pypy/objspace/std/test/test_lengthhint.py
--- a/pypy/objspace/std/test/test_lengthhint.py
+++ b/pypy/objspace/std/test/test_lengthhint.py
@@ -32,6 +32,12 @@
             space.call_method(w_reversed, '__length_hint__')) == self.SIZE
         self._test_length_hint(w_reversed)
 
+    def test_xrange(self):
+        space = self.space
+        w_xrange = space.call_method(space.builtin, 'xrange',
+                                     space.newint(self.SIZE))
+        self._test_length_hint(w_xrange)
+
     def test_default(self):
         space = self.space
         assert length_hint(space, space.w_False, 3) == 3


More information about the pypy-commit mailing list