summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-03-15 21:43:38 (GMT)
committerGeorg Brandl <georg@python.org>2009-03-15 21:43:38 (GMT)
commited4cefbedd1817247b94e5880f850bc1c3f6628d (patch)
tree315fb597d9ee701d0a828cde0490af4d4ba7ab7a
parent3259ef3dff534dd0c106905ffa6e14d8fe7181e1 (diff)
downloadcpython-ed4cefbedd1817247b94e5880f850bc1c3f6628d.zip
cpython-ed4cefbedd1817247b94e5880f850bc1c3f6628d.tar.gz
cpython-ed4cefbedd1817247b94e5880f850bc1c3f6628d.tar.bz2
Fix a small nit in the error message if bool() falls back on __len__ and it returns the wrong type: it would tell the user that __nonzero__ should return bool or int.
-rw-r--r--Objects/typeobject.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 1df37d1..4c397f7 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -5096,6 +5096,7 @@ slot_nb_nonzero(PyObject *self)
PyObject *func, *args;
static PyObject *nonzero_str, *len_str;
int result = -1;
+ int using_len = 0;
func = lookup_maybe(self, "__nonzero__", &nonzero_str);
if (func == NULL) {
@@ -5104,6 +5105,7 @@ slot_nb_nonzero(PyObject *self)
func = lookup_maybe(self, "__len__", &len_str);
if (func == NULL)
return PyErr_Occurred() ? -1 : 1;
+ using_len = 1;
}
args = PyTuple_New(0);
if (args != NULL) {
@@ -5114,8 +5116,10 @@ slot_nb_nonzero(PyObject *self)
result = PyObject_IsTrue(temp);
else {
PyErr_Format(PyExc_TypeError,
- "__nonzero__ should return "
+ "%s should return "
"bool or int, returned %s",
+ (using_len ? "__len__"
+ : "__nonzero__"),
temp->ob_type->tp_name);
result = -1;
}