Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r59330:51728673df09
Date: 2012-12-05 11:28 -0800
http://bitbucket.org/pypy/pypy/changeset/51728673df09/
Log: py3 is stricter about __len__ results
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -271,7 +271,7 @@
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"))
diff --git a/pypy/objspace/test/test_descroperation.py
b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -648,6 +648,7 @@
raises(ValueError, bool, X())
def test_len_custom__int__(self):
+ import sys
class X(object):
def __init__(self, x):
self.x = x
@@ -656,14 +657,11 @@
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__
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit