[Python-ideas] Deprecating the old-style sequence protocol

Nick Coghlan ncoghlan at gmail.com
Mon Dec 28 21:59:16 EST 2015


On 28 December 2015 at 03:04, Guido van Rossum <guido at python.org> wrote:
> If we really want a way to turn
> something that just supports __getitem__ into an Iterable maybe we can
> provide an additional ABC for that purpose; let's call it a HalfSequence
> until we've come up with a better name. (We can't use Iterable for this
> because Iterable should not reference __getitem__.)

Perhaps collections.abc.Indexable would work? Invariant:

    for idx, val in enumerate(container):
        assert container[idx] is val

That is, while enumerate() accepts any iterable, Indexable containers
have the additional property that the contained values can be looked
up by their enumeration index. Mappings (even ordered ones) don't
qualify, since they offer a key:value lookup, but enumerating them
produces an index:key relationship.

Regards,
Nick.

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


More information about the Python-ideas mailing list