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 <rep...@bugs.python.org>
<http://bugs.python.org/issue29727>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to