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

Andrew Barnert abarnert at yahoo.com
Tue Jan 5 13:17:42 EST 2016


On Jan 5, 2016, at 09:17, Alexander Walters <tritium-list at sdamon.com> wrote:
> 
>> On 1/5/2016 11:45, Guido van Rossum wrote:
>> since the arguments to __getitem__ are supposed to be objects with an __index__ method
> 
> ...In the context of classic iteration only?

Basically, in the context of what makes a sequence different from a mapping.

The idea here is to have a way to signal that a class follows the old-style sequence protocol, as opposed to being a mapping or some other use of __getitem__: you can access its elements by subscripting it with indexes from 0 up to the first one that raises IndexError (or up to __len__, if you provide it, but that isn't necessary). But this doesn't have to be airtight for type proofs or anything; if your class inherits from Indexable but then accepts integers too large to fit in an Index, that's fine.



More information about the Python-ideas mailing list