[Python-ideas] __iter__ implies __contains__?

Nick Coghlan ncoghlan at gmail.com
Sun Oct 2 03:01:08 CEST 2011


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
and the sequence of checks here is simply the longstanding one of
permitting containment tests on any iterable by default, and providing
default iterators for sequences that don't provide their own.

However, +1 for adding an IOBase __contains__ that raises TypeError.
This will need to go through the DeprecationError dance, though (i.e.
for 3.3, issue the warning before falling back on the current
iteration semantics). The current semantics are strange, but it's well
within the realm of possibility for someone to be relying on them.

Regards,
Nick.

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



More information about the Python-ideas mailing list