[Python-ideas] Deprecating the old-style sequence protocol
Guido van Rossum
guido at python.org
Mon Jan 4 15:31:48 EST 2016
[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 at yahoo.com> wrote:
> On Dec 27, 2015, at 09:04, Guido van Rossum <guido at 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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160104/b5a07ac4/attachment.html>
More information about the Python-ideas
mailing list