From: Raymond Hettinger Date: Thu, 9 Oct 2003 20:51:07 +0000 (+0000) Subject: SF patch #820195: make object.__contains__() returns True or False instead X-Git-Tag: v2.3.3c1~143 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b560bc648a42d7c6a586852cd695309434c45ac;p=thirdparty%2FPython%2Fcpython.git SF patch #820195: make object.__contains__() returns True or False instead of 1 or 0. Backport Guido's fix to the default __contains__() and to proxy_has_key() so they will properly return booleans instead of integers. --- diff --git a/Misc/NEWS b/Misc/NEWS index a92abc9dc8c2..7cdaa2d0900a 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,12 @@ What's New in Python 2.3.3c1? *Release date: XXX * +Core and builtins +----------------- + +- Patch #820195: object.__contains__() now returns True or False instead + of 1 or 0. + Extension modules ----------------- diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 745f95dca59b..ec4ea56f22df 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -709,7 +709,10 @@ static PySequenceMethods proxy_as_sequence = { static PyObject * proxy_has_key(proxyobject *pp, PyObject *key) { - return PyInt_FromLong(PySequence_Contains(pp->dict, key)); + int res = PySequence_Contains(pp->dict, key); + if (res < 0) + return NULL; + return PyBool_FromLong(res); } static PyObject * diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 2a7df8aa6326..b07ce2e6fe20 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3562,7 +3562,8 @@ wrap_objobjproc(PyObject *self, PyObject *args, void *wrapped) res = (*func)(self, value); if (res == -1 && PyErr_Occurred()) return NULL; - return PyInt_FromLong((long)res); + else + return PyBool_FromLong(res); } static PyObject *