[pypy-commit] pypy length-hint: modifications from PEP 424

pjenvey noreply at buildbot.pypy.org
Fri Sep 14 21:25:00 CEST 2012


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: length-hint
Changeset: r57353:2aef3dc2e53a
Date: 2012-09-14 12:23 -0700
http://bitbucket.org/pypy/pypy/changeset/2aef3dc2e53a/

Log:	modifications from PEP 424

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -945,9 +945,10 @@
                     e.match(self, self.w_AttributeError)):
                 raise
             return default
+        if self.is_w(w_hint, self.w_NotImplemented):
+            return default
 
-        hint = self.int_w(w_hint)
-        return default if hint < 0 else hint
+        return max(self.int_w(w_hint), 0)
 
     def fixedview(self, w_iterable, expected_length=-1):
         """ A fixed list view of w_iterable. Don't modify the result
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
@@ -39,6 +39,17 @@
         space = self.space
         assert space.length_hint(space.w_False, 3) == 3
 
+    def test_NotImplemented(self):
+        from pypy.interpreter.error import OperationError
+        space = self.space
+        w_foo = space.appexec([], """():
+            class Foo(object):
+                def __length_hint__(self):
+                    return NotImplemented
+            return Foo()
+        """)
+        assert space.length_hint(w_foo, 3) == 3
+
     def test_exc(self):
         from pypy.interpreter.error import OperationError
         space = self.space


More information about the pypy-commit mailing list