Author abarnert
Recipients abarnert
Date 2016-01-01.22:00:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This came up as a side issue in the -ideas discussion on deprecating the old-style sequence protocol that came out of Guido's suggestion on (

> 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.)

I'll file a patch this weekend. But in case there's anything to bikeshed, here are the details:

* Reversible is a subclass of Iterable.
 * It has a single abstract method, __reversed__, with no default implementation.
 * Its subclass hook that checks for __reversed__ existing and not being None.
* Sequence is a subclass of Reversible, Sized, and Container rather than directly of Iterable, Sized, and Container.

Builtins tuple and list, and any subclasses of them, will be Reversible because they register with Sequence or MutableSequence. Subclasses of will be Reversible (and should be, as they inherit Sequence.__reversed__). Custom old-style sequences will not be Reversible, even though reversed works on them.

Builtins dict, set, and frozenset, and any subclasses of them, will not be Reversible (unless they add a __reversed__ method, as OrderedDict does). Subclasses of will not be Reversible (and should not be, as, assuming #25864 goes through, they inherit Mapping.__reversed__=None) (unless they add a __reversed__ method, as most third-party sorted-dict types do).

I'll include tests for all of those things.

I believe this is all exactly parallel with, and will make compatible with typing.Reversible[...] in exactly the same way is compatible with typing.Iterable[...].

Alternatives: We could make Reversible independent of Iterable. Alternatively, we could make it subclass both Iterable and Sized instead of just Iterable. But I think this is the simplest place to slot it in.
Date User Action Args
2016-01-01 22:00:33abarnertsetrecipients: + abarnert
2016-01-01 22:00:33abarnertsetmessageid: <>
2016-01-01 22:00:33abarnertlinkissue25987 messages
2016-01-01 22:00:31abarnertcreate