mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Require that __nonzero__() return a bool or exactly an int.
This commit is contained in:
parent
25b5358cf2
commit
3e3159ce6a
1 changed files with 2 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue