[Python-ideas] __iter__ implies __contains__?

Nick Coghlan ncoghlan at gmail.com
Sun Oct 2 04:30:21 CEST 2011


On Sat, Oct 1, 2011 at 9:21 PM, Chris Rebert <pyideas at rebertia.com> wrote:
> Actually, my suggestion was just that Sequence is one possible (but
> clean) way to obtain the behavior; one could *of course* reimplement
> the functionality without recourse to Sequence if they desired.

But why would that would forcing everyone implementation standard
sequences to reimplement the wheel be an improvement over the status
quo? It would be like removing the check for "x.__len__() == 0" from
boolean conversions.

Duck-typed fallback protocols mean that you get some behaviour for
free without inheriting from anything in particular. If there's a
protocol that's a problem in a given case, then disable it or *just
don't use it* (e.g. people don't *do* containment tests on infinite
iterators, or, if they do, they quickly learn that triggering infinite
loops is a bad idea).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list