summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-02-28 15:01:46 (GMT)
committerGuido van Rossum <guido@python.org>2000-02-28 15:01:46 (GMT)
commit46c6b20392ba48280701f132321a06a1699429e9 (patch)
tree8afed17dfdfd2f8fd53bcac61f151365d3100ad9 /Objects
parentcecb27a49ca1285fc6fb3190d52768abf85847d1 (diff)
downloadcpython-46c6b20392ba48280701f132321a06a1699429e9.zip
cpython-46c6b20392ba48280701f132321a06a1699429e9.tar.gz
cpython-46c6b20392ba48280701f132321a06a1699429e9.tar.bz2
Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This
patches PySequence_Contains() to check for a valid sq_contains field. More to follow.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 5ee53ee..739d9d9 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1139,7 +1139,14 @@ PySequence_Contains(w, v) /* v in w */
}
return 0;
}
-
+ if(PyType_HasFeature(w->ob_type, Py_TPFLAGS_HAVE_SEQUENCE_IN)) {
+ sq = w->ob_type->tp_as_sequence;
+ if(sq != NULL && sq->sq_contains != NULL)
+ return (*sq->sq_contains)(w, v);
+ }
+
+ /* If there is no better way to check whether an item is is contained,
+ do it the hard way */
sq = w->ob_type->tp_as_sequence;
if (sq == NULL || sq->sq_item == NULL) {
PyErr_SetString(PyExc_TypeError,