This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author abarnert
Recipients abarnert, abarry, curioswati, gvanrossum, r.david.murray, rhettinger, serhiy.storchaka, terry.reedy
Date 2015-12-26.20:22:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1451161365.54.0.650620428128.issue25864@psf.upfronthosting.co.za>
In-reply-to
Content
> Perhaps there is a bug in typing.Reversible. It doesn't accept all types supported by reversed().

> ... And accepts types that don't work with reversed().

The problem is the way the two are defined:

* Reversible is true if you implement __reversed__
* reverse works if you implement __reversed__ or implement the old-style sequence protocol.

That explains why it doesn't work on tuple, bytearray, etc. Iterable actually has the exact same problem, but, because it's a supertype of Sequence, and we have explicit Sequence.register(tuple) and MutableSequence.register(bytearray) in collections.abc, and typing.Iterable specifies collections.abc.Iterable as its "extra", it all works out.

We could do the same for Reversible: add a collections.abc.Reversible, make it a subtype of Iterable and make Sequence a subtype of Reversible instead of Iterable, and make that the extra for typing.Reversible. Then it would work for all of those builtin types (and many third-party types that explicitly register with Sequence), just as Iterable does.

But that only solves the problem in one direction. To solve it in the other direction, we'd need some way to either explicitly mark a method as not implemented (maybe setting it to None, or to any non-callable, or any data descriptor?) that ABC subclass hooks and/or typing checks are expected to understand, or unregister a class with an ABC so that it isn't a subtype even if it passes the implicit hooks.

Or... could we just drop Reversible as an implicit protocol? The lack of an explicit "deny" mechanism for implicit protocols and ABCs is a more general problem, but if this is the only actual instance of that problem in real life, do we need to solve the general problem? If not, there's no obvious way to define typing.Reversible that isn't wrong, it doesn't have a corresponding ABC, it doesn't seem like it will be useful often enough to be worth the problems it causes, and I doubt there's much real-life code out there already depending on it, so that seems a lot easier.
History
Date User Action Args
2015-12-26 20:22:45abarnertsetrecipients: + abarnert, gvanrossum, rhettinger, terry.reedy, r.david.murray, serhiy.storchaka, abarry, curioswati
2015-12-26 20:22:45abarnertsetmessageid: <1451161365.54.0.650620428128.issue25864@psf.upfronthosting.co.za>
2015-12-26 20:22:45abarnertlinkissue25864 messages
2015-12-26 20:22:45abarnertcreate