]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF patch #820195: make object.__contains__() returns True or False instead
authorRaymond Hettinger <python@rcn.com>
Thu, 9 Oct 2003 20:51:07 +0000 (20:51 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 9 Oct 2003 20:51:07 +0000 (20:51 +0000)
   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.

Misc/NEWS
Objects/descrobject.c
Objects/typeobject.c

index a92abc9dc8c21dbd7d1a563e540f59272204de6b..7cdaa2d0900a29465b799d0a04584da36edeb881 100644 (file)
--- 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
 -----------------
 
index 745f95dca59b7f5525d0d972a40663e635e6aded..ec4ea56f22dfc711b9b681697efefadec3b2505a 100644 (file)
@@ -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 *
index 2a7df8aa6326ad7e6462dbe0c1a9d60efcfffb99..b07ce2e6fe20cf2a0e549da5668d9e153b5a36a3 100644 (file)
@@ -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 *