Commits

Philip Jenvey committed 5172867

py3 is stricter about __len__ results

  • Participants
  • Parent commits dfcd72d
  • Branches py3k

Comments (0)

Files changed (2)

pypy/objspace/descroperation.py

 
     def _check_len_result(space, w_obj):
         # Will complain if result is too big.
-        result = space.int_w(space.int(w_obj))
+        result = space.int_w(w_obj)
         if result < 0:
             raise OperationError(space.w_ValueError,
                                  space.wrap("__len__() should return >= 0"))

pypy/objspace/test/test_descroperation.py

         raises(ValueError, bool, X())
 
     def test_len_custom__int__(self):
+        import sys
         class X(object):
             def __init__(self, x):
                 self.x = x
             def __int__(self):
                 return self.x
 
-        l = len(X(3.0))
-        assert l == 3 and type(l) is int
-        assert X(3.0)
-        assert not X(0.0)
-        l = len(X(X(2)))
-        assert l == 2 and type(l) is int
-        assert X(X(2))
-        assert not X(X(0))
+        raises(TypeError, len, X(3.0))
+        raises(TypeError, len, X(X(2)))
+        raises(TypeError, bool, X(3.0))
+        raises(TypeError, bool, X(X(2)))
+        raises(OverflowError, len, X(sys.maxsize + 1))
 
     def test_sane_len(self):
         # this test just tests our assumptions about __len__