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

[Adding python-ideas back -- I'm not sure why you dropped it but it looks like an oversight, not intentional] On Fri, Jan 1, 2016 at 2:25 PM, Andrew Barnert <abarnert@yahoo.com> wrote:
On Dec 27, 2015, at 09:04, Guido van Rossum <guido@python.org> wrote:
If we want some way to turn something that just defines __getitem__ and __len__ into a proper sequence, it should just be made to inherit from Sequence, which supplies the default __iter__ and __reversed__. (Registration is *not* good enough here.)
So, if I understand correctly, you're hoping that we can first make the old-style sequence protocol unnecessary, except for backward compatibility, and then maybe change the docs to only mention it for backward compatibility, and only then deprecate it?
That sounds about right.
I think it's worth doing those first two steps, but not actually deprecating it, at least while Python 2.7 is still around; otherwise, for dual-version code, something like Steven D'Aprano's "Squares" type would have to copy Indexable from the 3.x stdlib or get it from some third-party module like six or backports.collections.
Yes, that's fine. Deprecation sometimes just has to take a really long time.
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__.)
#25988 (using Nick's name Indexable, and the details from that post).
Oh, interesting. Though I have misgivings about that name.
I also think it's fine to introduce Reversible as another ABC and carefully fit it into the existing hierarchy. It should be a one-trick pony and be another base class for Sequence; it should not have a default implementation. (But this has been beaten to death in other threads -- it's time to just file an issue with a patch.)
#25987.
Thanks! -- --Guido van Rossum (python.org/~guido)

On Jan 4, 2016, at 12:31, Guido van Rossum <guido@python.org> wrote:
On Fri, Jan 1, 2016 at 2:25 PM, Andrew Barnert <abarnert@yahoo.com> wrote: On Dec 27, 2015, at 09: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__.)
#25988 (using Nick's name Indexable, and the details from that post).
Oh, interesting. Though I have misgivings about that name.
Now that you mention it, I can see the confusion. I interpreted Nick's "Indexable" to mean "subscriptable by indexes (and slices of indexes)" as opposed to "subscriptable by arbitrary keys". But if I didn't already know what he intended, I suppose I could have instead guessed "usable as an index", which would be very misleading. There don't seem to be any existing terms for this that don't relate to "sequence", so maybe your HalfSequence (or Sequential or SequentiallySubscriptable or something even more horrible than that last one?) is the best option? Or, hopefully, someone _can_ come up with a better name. :)

On 5 January 2016 at 12:46, Andrew Barnert via Python-ideas <python-ideas@python.org> wrote:
On Jan 4, 2016, at 12:31, Guido van Rossum <guido@python.org> wrote:
On Fri, Jan 1, 2016 at 2:25 PM, Andrew Barnert <abarnert@yahoo.com> wrote:
On Dec 27, 2015, at 09: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__.)
#25988 (using Nick's name Indexable, and the details from that post).
Oh, interesting. Though I have misgivings about that name.
Now that you mention it, I can see the confusion. I interpreted Nick's "Indexable" to mean "subscriptable by indexes (and slices of indexes)" as opposed to "subscriptable by arbitrary keys". But if I didn't already know what he intended, I suppose I could have instead guessed "usable as an index", which would be very misleading.
There don't seem to be any existing terms for this that don't relate to "sequence", so maybe your HalfSequence (or Sequential or SequentiallySubscriptable or something even more horrible than that last one?) is the best option?
Or, hopefully, someone _can_ come up with a better name. :)
I mainly suggested Indexable because it was the least-worst name I could think of, and I'd previously suggested Index as the name for "has an __index__ method" (in the context of typing, but it would also work in the context of collections.abc). The main alternative I've thought of is "IterableByIndex", which is both explicit and accurate, with the only strike against it being length. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

Devils Advocate: Please don't make me press shift more than twice in a base class name if you expect me to use it. It just makes annoying avoidable typos more common. 'Subscripted' sounds good to me, if that's worth anything. On 1/5/2016 00:50, Nick Coghlan wrote:
On 5 January 2016 at 12:46, Andrew Barnert via Python-ideas <python-ideas@python.org> wrote:
On Jan 4, 2016, at 12:31, Guido van Rossum <guido@python.org> wrote:
On Fri, Jan 1, 2016 at 2:25 PM, Andrew Barnert <abarnert@yahoo.com> wrote:
On Dec 27, 2015, at 09: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__.) #25988 (using Nick's name Indexable, and the details from that post). Oh, interesting. Though I have misgivings about that name.
Now that you mention it, I can see the confusion. I interpreted Nick's "Indexable" to mean "subscriptable by indexes (and slices of indexes)" as opposed to "subscriptable by arbitrary keys". But if I didn't already know what he intended, I suppose I could have instead guessed "usable as an index", which would be very misleading.
There don't seem to be any existing terms for this that don't relate to "sequence", so maybe your HalfSequence (or Sequential or SequentiallySubscriptable or something even more horrible than that last one?) is the best option?
Or, hopefully, someone _can_ come up with a better name. :) I mainly suggested Indexable because it was the least-worst name I could think of, and I'd previously suggested Index as the name for "has an __index__ method" (in the context of typing, but it would also work in the context of collections.abc).
The main alternative I've thought of is "IterableByIndex", which is both explicit and accurate, with the only strike against it being length.
Cheers, Nick.

Or maybe Indexable is fine after all, since the arguments to __getitem__ are supposed to be objects with an __index__ method (e.g. Integral, but not Real). BTW, Maybe Index needs to be added to numbers.py as an ABC? PEP 357, which introduced it, sounds like it pre-dates ABCs. On Tue, Jan 5, 2016 at 6:13 AM, Alexander Walters <tritium-list@sdamon.com> wrote:
Devils Advocate: Please don't make me press shift more than twice in a base class name if you expect me to use it. It just makes annoying avoidable typos more common.
'Subscripted' sounds good to me, if that's worth anything.
On 1/5/2016 00:50, Nick Coghlan wrote:
On 5 January 2016 at 12:46, Andrew Barnert via Python-ideas <python-ideas@python.org> wrote:
On Jan 4, 2016, at 12:31, Guido van Rossum <guido@python.org> wrote:
On Fri, Jan 1, 2016 at 2:25 PM, Andrew Barnert <abarnert@yahoo.com> wrote:
On Dec 27, 2015, at 09: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__.)
#25988 (using Nick's name Indexable, and the details from that post).
Oh, interesting. Though I have misgivings about that name.
Now that you mention it, I can see the confusion. I interpreted Nick's "Indexable" to mean "subscriptable by indexes (and slices of indexes)" as opposed to "subscriptable by arbitrary keys". But if I didn't already know what he intended, I suppose I could have instead guessed "usable as an index", which would be very misleading.
There don't seem to be any existing terms for this that don't relate to "sequence", so maybe your HalfSequence (or Sequential or SequentiallySubscriptable or something even more horrible than that last one?) is the best option?
Or, hopefully, someone _can_ come up with a better name. :)
I mainly suggested Indexable because it was the least-worst name I could think of, and I'd previously suggested Index as the name for "has an __index__ method" (in the context of typing, but it would also work in the context of collections.abc).
The main alternative I've thought of is "IterableByIndex", which is both explicit and accurate, with the only strike against it being length.
Cheers, Nick.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido)

On Jan 5, 2016, at 09:17, Alexander Walters <tritium-list@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.
participants (4)
-
Alexander Walters
-
Andrew Barnert
-
Guido van Rossum
-
Nick Coghlan