SF bug #820397: __nonzero__() returns 1/0

Altered to return a PyBool instead of a PyInt.

Backport candidate.
This commit is contained in:
Raymond Hettinger 2003-10-11 17:29:04 +00:00
parent 40b9df2fea
commit f34f2646a1
1 changed files with 15 additions and 1 deletions

View File

@ -3325,6 +3325,20 @@ wrap_inquiry(PyObject *self, PyObject *args, void *wrapped)
return PyInt_FromLong((long)res);
}
static PyObject *
wrap_inquirypred(PyObject *self, PyObject *args, void *wrapped)
{
inquiry func = (inquiry)wrapped;
int res;
if (!PyArg_ParseTuple(args, ""))
return NULL;
res = (*func)(self);
if (res == -1 && PyErr_Occurred())
return NULL;
return PyBool_FromLong((long)res);
}
static PyObject *
wrap_binaryfunc(PyObject *self, PyObject *args, void *wrapped)
{
@ -4914,7 +4928,7 @@ static slotdef slotdefs[] = {
UNSLOT("__pos__", nb_positive, slot_nb_positive, wrap_unaryfunc, "+x"),
UNSLOT("__abs__", nb_absolute, slot_nb_absolute, wrap_unaryfunc,
"abs(x)"),
UNSLOT("__nonzero__", nb_nonzero, slot_nb_nonzero, wrap_inquiry,
UNSLOT("__nonzero__", nb_nonzero, slot_nb_nonzero, wrap_inquirypred,
"x != 0"),
UNSLOT("__invert__", nb_invert, slot_nb_invert, wrap_unaryfunc, "~x"),
BINSLOT("__lshift__", nb_lshift, slot_nb_lshift, "<<"),