Guido van Rossum wrote:
Shouldn't 'in' be a slot of the sequence methods ? I'd suggest creating a new tp_flag bit and then extending tp_as_sequence with:
binaryfunc sq_contains;
plus of course add an abstract function to abstract.c:
PySequence_Contain(PyObject *container, PyObject *element)
That function already exists, spelled "PySequence_Contains" (currently it does the C equivalent of
for i in container: if element == i: return 1 return 0
Hmm, I must have overseen that one... the above only works for sequences, while 'in'ness only need an unordered set to work. Perhaps we do need an abstraction for unordered object containers after all, just like Moshe suggested. I don't think it's top-priority, though...
I'm not entirely sure whether the 'contains' slot should be part of the as_sequence struct, but I suppose it makes sense historically. (The as_number, as_sequece, as_mapping structs don't make sense at all in the grand scheme of things, but we're stuck with them for the time being.)
Doens't really matter where we put it -- the type object is a mess already ;-) -- Marc-Andre Lemburg ______________________________________________________________________ Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/