On Mon, Oct 03, 2011 at 06:31:08AM +1100, Steven D'Aprano wrote:
Devin Jeanpierre wrote:
Since iteration over elements is at the heart of containment tests, the same reasoning applies to __contains__.
I was with you for the old-style sequence iteration API, but you've lost me here. I *can* imagine use-cases where "in" shouldn't work: pretty much any iterator. Doesn't it seem strange that `x in A` should succeed, but then `x in A` should fail?
No. That is implied by the iterator protocol
This is exactly the issue that is being discussed. In my very humble opinion classes that produce non-restartable iterators should not allow containment tests to use iterators. Oleg. -- Oleg Broytman http://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN.