From 6b560bc648a42d7c6a586852cd695309434c45ac Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 9 Oct 2003 20:51:07 +0000 Subject: 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. --- Misc/NEWS | 6 ++++++ Objects/descrobject.c | 5 ++++- Objects/typeobject.c | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index a92abc9..7cdaa2d 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 745f95d..ec4ea56 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 2a7df8a..b07ce2e 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 * -- cgit v0.12