Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r58793:0f07e572128b
Date: 2012-11-08 12:11 -0800
http://bitbucket.org/pypy/pypy/changeset/0f07e572128b/
Log: bool now rejects plain ints
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -239,11 +239,10 @@
w_restype = space.type(w_res)
# Note there is no check for bool here because the only possible
# instances of bool are w_False and w_True, which are checked above.
- if space.is_w(w_restype, space.w_int):
- return space.int_w(w_res) != 0
- else:
- msg = "__bool__ should return bool or integer"
- raise OperationError(space.w_TypeError, space.wrap(msg))
+ typename = space.type(w_obj).getname(space)
+ raise operationerrfmt(space.w_TypeError,
+ "__bool__ should return bool, returned %s",
+ typename)
def nonzero(space, w_obj):
if space.is_true(w_obj):
diff --git a/pypy/objspace/std/test/test_boolobject.py
b/pypy/objspace/std/test/test_boolobject.py
--- a/pypy/objspace/std/test/test_boolobject.py
+++ b/pypy/objspace/std/test/test_boolobject.py
@@ -53,3 +53,10 @@
def test_cant_subclass_bool(self):
raises(TypeError, "class b(bool): pass")
+
+ def test_convert_to_bool(self):
+ check = lambda o: raises(TypeError, bool, o)
+ class Spam(int):
+ def __bool__(self):
+ return 1
+ raises(TypeError, bool, Spam())
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit