[New-bugs-announce] [issue29727] collections.abc.Reversible doesn't fully support the reversing protocol
Serhiy Storchaka
report at bugs.python.org
Sun Mar 5 13:49:23 EST 2017
New submission from Serhiy Storchaka:
collections.abc.Reversible doesn't work with types that are supported by reserved() but neither have the __reversed__ method nor are explicitly registered as collections.abc.Sequence. For example:
>>> issubclass(array.array, collections.abc.Reversible)
False
The reversing protocol as well as the iterating protocol is supported not only by special method, but implicitly if the class has implemented __getitem__ and __len__ methods.
>>> class Counter(int):
... def __getitem__(s, i): return i
... def __len__(s): return s
...
>>> list(reversed(Counter(10)))
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
>>> issubclass(Counter, collections.abc.Reversible)
False
typing.Reversible starves from the same bug. See https://github.com/python/typing/issues/170.
----------
components: Library (Lib)
messages: 289039
nosy: gvanrossum, rhettinger, serhiy.storchaka, stutzbach
priority: normal
severity: normal
status: open
title: collections.abc.Reversible doesn't fully support the reversing protocol
type: behavior
versions: Python 3.6, Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29727>
_______________________________________
More information about the New-bugs-announce
mailing list