[Python-ideas] __iter__ implies __contains__?

Masklinn masklinn at masklinn.net
Sun Oct 2 13:21:35 CEST 2011


On 2011-10-02, at 03:01 , Nick Coghlan wrote:

> On Sat, Oct 1, 2011 at 4:24 PM, Chris Rebert <pyideas at rebertia.com> wrote:
>> Requiring the explicit marking of a class as a sequence by inheriting
>> from the Sequence ABC in order to get such default behavior "for free"
>> seems quite reasonable. And having containment defined by default on
>> potentially-infinite iterators seems unwise. +1 on the suggested
>> removals.
> 
> -1 to any removals - fallback protocols are the heart of duck-typing
I very much disagree with this assertion. In fact I'd make the opposite
one: fallback protocols are a perversion of duck-typing and only serve
to make it less reliable and less predictable.

In keeping with ducks, you were looking for one, didn't find anything
which quacked or looked like a duck. The fallback protocol kicks in,
you get something with feathers which you found near water and went
"good enough". Now you drop it from 10000m because you're looking into
the efficiency of a duck's flight starting airborne, and observe your
quite dismayed penguin barreling towards the ground.

A few seconds later, you find yourself not with additional experimental
data but with a small indentation in the earth and a big mess all over
it.




More information about the Python-ideas mailing list