-
Notifications
You must be signed in to change notification settings - Fork 258
typing.Reversible doesn't fully support the reversing protocol #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yeah, the The place where this really should be implemented is in the type checker, e.g. mypy (https://github.com/JukkaL/mypy). I don't know whether mypy currently supports this, but it's worth trying and searching its issue tracker. (I would, but I'm home sick and can't concentrate very long.) |
This is the same problem as
Alternatively, is |
The type checker (e.g. mypy) is independent from the issubclass() |
IOW Reversible does get things right in practice (in the type checker). FWIW, maybe we should try to deprecate supporting iteration using the old-style protocol? It's really a very old backwards compatibility measure (from when iterators were first introduced). Then eventually we could do the same for reversing using the old-style protocol. |
The last time deprecating the old-style protocol came up, Stephen d'Aprano strongly objected (http://article.gmane.org/gmane.comp.python.ideas/23369/match=old+sequence+protocol), citing an earlier objection by Raymond Hettinger (which I don't have a link for). |
On Sat, Dec 26, 2015 at 6:24 PM, Andrew Barnert notifications@github.com
--Guido van Rossum (python.org/~guido) |
The issue is fixed for |
@serhiy-storchaka Yes, I also noticed this some time ago. But now |
If this is still an issue, it should be reported to bpo. |
typing.Reversible
doesn't work with types that are supported byreserved()
but don't have the__reversed__
method. E.g. tuple, str, bytes, bytearray, and array.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.The text was updated successfully, but these errors were encountered: