summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2003-06-27 17:38:27 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2003-06-27 17:38:27 (GMT)
commit3e3159ce6ac6dc27d17b99ba758c1322a67427bb (patch)
treee8d64ad64deee281afe2c22c81a122cfea33a47e /Objects
parent25b5358cf2bfb12b8e1c24455688787e57243573 (diff)
downloadcpython-3e3159ce6ac6dc27d17b99ba758c1322a67427bb.zip
cpython-3e3159ce6ac6dc27d17b99ba758c1322a67427bb.tar.gz
cpython-3e3159ce6ac6dc27d17b99ba758c1322a67427bb.tar.bz2
Require that __nonzero__() return a bool or exactly an int.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 7c4e744..a8c8b15 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4196,18 +4196,14 @@ slot_nb_nonzero(PyObject *self)
PyObject *temp = PyObject_Call(func, args, NULL);
Py_DECREF(args);
if (temp != NULL) {
- if (PyInt_Check(temp)) {
- /* XXX need to guard against recursion here */
- result = PyObject_IsTrue(temp);
- }
- else if (PyBool_Check(temp))
+ if (PyInt_CheckExact(temp) || PyBool_Check(temp))
result = PyObject_IsTrue(temp);
else {
PyErr_Format(PyExc_TypeError,
"__nonzero__ should return "
"bool or int, returned %s",
temp->ob_type->tp_name);
- result = NULL;
+ result = -1;
}
Py_DECREF(temp);
}