Message 256910 - Python tracker (original) (raw)

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 "", line 1, in TypeError: 'NoneType' object is not callable issubclass(L, typing.Reversible) True