[issue13667] __contains__ method behavior
João Bernardo
report at bugs.python.org
Wed Dec 28 18:22:55 CET 2011
João Bernardo <jbvsmo at gmail.com> added the comment:
Using my poor grep abilities I found that on Objects/typeobject.c
(I replaced some declarations/error checking from the code with ...)
static int
slot_sq_contains(PyObject *self, PyObject *value) {
...
func = lookup_maybe(self, "__contains__", &contains_str);
if (func != NULL) {
...
res = PyObject_Call(func, args, NULL);
...
if (res != NULL) {
result = PyObject_IsTrue(res);
Py_DECREF(res);
}
}
else if (! PyErr_Occurred()) {
/* Possible results: -1 and 1 */
result = (int)_PySequence_IterSearch(self, value,
PY_ITERSEARCH_CONTAINS);
}
}
I don't know if I'm in the right place, but the function returns `int` and evaluates the result to 1 or 0 if __contains__ is found.
I also don't know what SQSLOT means, but unlike the other operators (which are defined as TPSLOT), `slot_sq_contains` is a function returning "int" while `slot_tp_richcompare` returns "PyObject *".
Why is that defined that way?
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13667>
_______________________________________
More information about the Python-bugs-list
mailing list