[Python-Dev] __contains__ hook: follow-up

Moshe Zadka Moshe Zadka <mzadka@geocities.com>
Sat, 5 Feb 2000 02:15:37 +0200 (IST)


I've sent a patch to patches@python.org which does the 'in' hook in the
pseudo-right way: adding a slot to the sequence methods structure, and
adding a flag to support it for backwards compatability.

Now that it's there, I've also changed instance method to use it, and to
map it to __contains__. The code there also has special-case for strings,
so if someone (maybe me) adds such a slot to strings, then the code will
only have to do the C equivalent of

try:
	obj.__contains__(whatever)
except AttributeError:
	for element in obj:
		if element == whatever:
			return 1
	return 0

Is this desirable? It shouldn't be too hard...

--
Moshe Zadka <mzadka@geocities.com>. 
INTERNET: Learn what you know.
Share what you don't.