-
Notifications
You must be signed in to change notification settings - Fork 268
Closed
Labels
resolution: out of scopeThe idea or discussion was out of scope for this repositoryThe idea or discussion was out of scope for this repository
Description
typing.Reversible
doesn't work with types that are supported by reserved()
but don't have the __reversed__
method. E.g. tuple, str, bytes, bytearray, and array.
>>> issubclass(tuple, typing.Reversible)
False
>>> issubclass(str, typing.Reversible)
False
>>> issubclass(bytes, typing.Reversible)
False
>>> issubclass(bytearray, typing.Reversible)
False
>>> issubclass(array.array, typing.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, typing.Reversible)
False
Metadata
Metadata
Assignees
Labels
resolution: out of scopeThe idea or discussion was out of scope for this repositoryThe idea or discussion was out of scope for this repository