Message289039
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. |
|
Date |
User |
Action |
Args |
2017-03-05 18:49:23 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, gvanrossum, rhettinger, stutzbach |
2017-03-05 18:49:23 | serhiy.storchaka | set | messageid: <1488739763.14.0.639498346483.issue29727@psf.upfronthosting.co.za> |
2017-03-05 18:49:23 | serhiy.storchaka | link | issue29727 messages |
2017-03-05 18:49:22 | serhiy.storchaka | create | |
|