[Python-ideas] Deprecating the old-style sequence protocol
Guido van Rossum
guido at python.org
Sun Dec 27 12:04:59 EST 2015
I think there's a lot of interesting stuff in this thread. Personally I
don't think we should strive to distinguish between mappings and sequences
structurally. We should instead continue to encourage inheriting from (or
registering with) the corresponding ABCs. The goal is to ensure that
there's one best-practice way to distinguish mappings from sequences, and
it's by using isinstance(x, Sequence) or isinstance(x, Mapping).
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.) 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__.)
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.)
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151227/83161b58/attachment.html>
More information about the Python-ideas
mailing list