[issue29727] collections.abc.Reversible doesn't fully support the reversing protocol

Raymond Hettinger report at bugs.python.org
Sun Mar 5 14:02:38 EST 2017


Raymond Hettinger added the comment:

I don't think this is a bug.  The purpose collections.abc.Reversible is to recognize type where the behavior has been guaranteed, not to recognize all types where it happens to work.

Part of the original reason for introducing ABCs in the first place was that in general there is no reliable way to detect whether a class defining __getitem__ is a sequence or a mapping.

A creator of such a class either needs to subclass from Sequence or register as a Sequence.  The fact that reversed(Counter(10)) happens to work is no more interesting that the fact Counter(10)[5] happens to work eventhough isinstance(Counter, Sequence) returns False.

----------
assignee:  -> rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29727>
_______________________________________


More information about the Python-bugs-list mailing list