Author serhiy.storchaka
Recipients abarnert, curioswati, ebarry, gvanrossum, r.david.murray, rhettinger, serhiy.storchaka, terry.reedy
Date 2015-12-23.13:24:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1450877051.59.0.888981600006.issue25864@psf.upfronthosting.co.za>
In-reply-to
Content
I agree that by default calling reversed() on mapping should raise a TypeError. But for now issubclass(collections.abc.Mapping, typing.Reversible) returns False. If add default __reversed__ implementation this test will return True. We have to find other way to make Mapping true non-reversible in all meanings.

Perhaps there is a bug in typing.Reversible. It doesn't accept all types supported by reversed().

>>> 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, typing.Reversible)
False

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

>>> class L(list):
...    __reversed__ = None
... 
>>> reversed(L())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
>>> issubclass(L, typing.Reversible)
True
History
Date User Action Args
2015-12-23 13:24:11serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, rhettinger, terry.reedy, r.david.murray, abarnert, ebarry, curioswati
2015-12-23 13:24:11serhiy.storchakasetmessageid: <1450877051.59.0.888981600006.issue25864@psf.upfronthosting.co.za>
2015-12-23 13:24:11serhiy.storchakalinkissue25864 messages
2015-12-23 13:24:11serhiy.storchakacreate