-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
collections.abc.Reversible #70175
Comments
This came up as a side issue in the -ideas discussion on deprecating the old-style sequence protocol that came out of Guido's suggestion on python/typing#170 (http://article.gmane.org/gmane.comp.python.ideas/37599):
I'll file a patch this weekend. But in case there's anything to bikeshed, here are the details:
Builtins tuple and list, and any subclasses of them, will be Reversible because they register with Sequence or MutableSequence. Subclasses of collections.abc.Sequence will be Reversible (and should be, as they inherit Sequence.__reversed__). Custom old-style sequences will not be Reversible, even though reversed works on them. Builtins dict, set, and frozenset, and any subclasses of them, will not be Reversible (unless they add a __reversed__ method, as OrderedDict does). Subclasses of collections.abc.Mapping will not be Reversible (and should not be, as, assuming bpo-25864 goes through, they inherit Mapping.__reversed__=None) (unless they add a __reversed__ method, as most third-party sorted-dict types do). I'll include tests for all of those things. I believe this is all exactly parallel with collections.abc.Iterable, and will make collections.abc.Reversible compatible with typing.Reversible[...] in exactly the same way collections.abc.Iterable is compatible with typing.Iterable[...]. Alternatives: We could make Reversible independent of Iterable. Alternatively, we could make it subclass both Iterable and Sized instead of just Iterable. But I think this is the simplest place to slot it in. |
Yes please. Thanks for thinking about all the edge cases here! |
Andrew, did you lose interest in this? We now have a PR for typing.py that expects this to be resolved: python/typing#194 |
I was not sure whether Andrew is still interested. I made a simple-minded patch following his proposal. I also added tests and changed docs accordingly. Note that I also changed the expected MRO for MutableSequence in one of the functools tests according to the new hierarchy (otherwise test_functools fails). Please review. PS: Some tests was skipped on my machine, here is the list: |
Looks good. I'll merge this in a sec. |
New changeset 07f73360ea8e by Guido van Rossum in branch 'default': |
Done. Thanks! |
I see that I forgot to include .. versionadded:: in the documentation. |
Because it's a change to collections.abc, it goes in 3.6 only. |
New changeset 7d9f7d7a21ae by Georg Brandl in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: