Commits

Philip Jenvey  committed 2aef3dc

modifications from PEP 424

  • Participants
  • Parent commits 737ed2b
  • Branches length-hint

Comments (0)

Files changed (2)

File pypy/interpreter/baseobjspace.py

                     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

File pypy/objspace/std/test/test_lengthhint.py

         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