Skip to content
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

Closed
abarnert mannequin opened this issue Jan 1, 2016 · 10 comments
Closed

collections.abc.Reversible #70175

abarnert mannequin opened this issue Jan 1, 2016 · 10 comments
Labels
docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@abarnert
Copy link
Mannequin

abarnert mannequin commented Jan 1, 2016

BPO 25987
Nosy @gvanrossum, @ilevkivskyi
Files
  • reversible.patch: A patch following the Andew's proposal
  • 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:

    assignee = None
    closed_at = <Date 2016-04-04.18:00:23.026>
    created_at = <Date 2016-01-01.22:00:33.076>
    labels = ['type-feature', 'library', 'docs']
    title = 'collections.abc.Reversible'
    updated_at = <Date 2016-04-18.05:26:11.865>
    user = 'https://bugs.python.org/abarnert'

    bugs.python.org fields:

    activity = <Date 2016-04-18.05:26:11.865>
    actor = 'python-dev'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2016-04-04.18:00:23.026>
    closer = 'gvanrossum'
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2016-01-01.22:00:33.076>
    creator = 'abarnert'
    dependencies = []
    files = ['42357']
    hgrepos = []
    issue_num = 25987
    keywords = ['patch']
    message_count = 10.0
    messages = ['257310', '257488', '262481', '262800', '262858', '262859', '262860', '263614', '263636', '263642']
    nosy_count = 5.0
    nosy_names = ['gvanrossum', 'docs@python', 'python-dev', 'abarnert', 'levkivskyi']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue25987'
    versions = []

    @abarnert
    Copy link
    Mannequin Author

    abarnert mannequin commented Jan 1, 2016

    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 also think it's fine to introduce Reversible as another ABC and carefully fit it into the existing hierarchy. It should be a one-trick pony and be another base class for Sequence; it should not have a default implementation. (But this has been beaten to death in other threads -- it's time to just file an issue with a patch.)

    I'll file a patch this weekend. But in case there's anything to bikeshed, here are the details:

    • Reversible is a subclass of Iterable.
    • It has a single abstract method, __reversed__, with no default implementation.
    • Its subclass hook that checks for __reversed__ existing and not being None.
    • Sequence is a subclass of Reversible, Sized, and Container rather than directly of Iterable, Sized, and Container.

    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.

    @abarnert abarnert mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jan 1, 2016
    @gvanrossum
    Copy link
    Member

    Yes please. Thanks for thinking about all the edge cases here!

    @gvanrossum
    Copy link
    Member

    Andrew, did you lose interest in this? We now have a PR for typing.py that expects this to be resolved: python/typing#194

    @ilevkivskyi
    Copy link
    Member

    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:
    test_bz2 test_curses test_dbm_gnu test_dbm_ndbm test_devpoll
    test_idle test_kqueue test_lzma test_msilib test_ossaudiodev
    test_smtpnet test_socketserver test_ssl test_startfile test_tcl
    test_timeout test_tix test_tk test_ttk_guionly test_ttk_textonly
    test_urllib2net test_urllibnet test_winreg test_winsound
    test_xmlrpc_net test_zipfile64

    @gvanrossum
    Copy link
    Member

    Looks good. I'll merge this in a sec.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 4, 2016

    New changeset 07f73360ea8e by Guido van Rossum in branch 'default':
    Add collections.Reversible. Patch by Ivan Levkivskyi. Fixes issue bpo-25987.
    https://hg.python.org/cpython/rev/07f73360ea8e

    @gvanrossum
    Copy link
    Member

    Done. Thanks!

    @ilevkivskyi
    Copy link
    Member

    I see that I forgot to include .. versionadded:: in the documentation.
    Will this go into 3.5.2 or in 3.6?

    @ilevkivskyi ilevkivskyi added the docs Documentation in the Doc dir label Apr 17, 2016
    @gvanrossum
    Copy link
    Member

    Because it's a change to collections.abc, it goes in 3.6 only.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 18, 2016

    New changeset 7d9f7d7a21ae by Georg Brandl in branch 'default':
    bpo-25987: add versionadded to Reversible.
    https://hg.python.org/cpython/rev/7d9f7d7a21ae

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants