On 28 December 2015 at 03:04, Guido van Rossum guido@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.