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

Add slicing support to collections.deque #61596

Closed
rhettinger opened this issue Mar 11, 2013 · 16 comments
Closed

Add slicing support to collections.deque #61596

rhettinger opened this issue Mar 11, 2013 · 16 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@rhettinger
Copy link
Contributor

BPO 17394
Nosy @rhettinger, @jcea, @larryhastings, @serhiy-storchaka, @MojoVampire
Files
  • deque_slices.patch
  • deque_slices_2.patch
  • deque_slices_3.patch
  • 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 = 'https://github.com/rhettinger'
    closed_at = <Date 2016-09-10.00:07:04.644>
    created_at = <Date 2013-03-11.03:20:21.596>
    labels = ['type-feature', 'library']
    title = 'Add slicing support to collections.deque'
    updated_at = <Date 2016-09-10.00:07:04.643>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2016-09-10.00:07:04.643>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2016-09-10.00:07:04.644>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2013-03-11.03:20:21.596>
    creator = 'rhettinger'
    dependencies = []
    files = ['41506', '41723', '42082']
    hgrepos = []
    issue_num = 17394
    keywords = ['patch']
    message_count = 16.0
    messages = ['183918', '190873', '197578', '243029', '257460', '258997', '259001', '259070', '259089', '259810', '259812', '261285', '267777', '272766', '275180', '275505']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'jcea', 'larry', 'serhiy.storchaka', 'josh.r']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue17394'
    versions = ['Python 3.6']

    @rhettinger
    Copy link
    Contributor Author

    Once added, use it in threading.Condition().

    @rhettinger rhettinger self-assigned this Mar 11, 2013
    @rhettinger rhettinger added the stdlib Python modules in the Lib dir label Mar 11, 2013
    @rhettinger
    Copy link
    Contributor Author

    The slicing support can be implemented using just rotates, appends, and pops.

    @rhettinger rhettinger removed their assignment Jun 9, 2013
    @rhettinger rhettinger added the type-feature A feature request or enhancement label Jun 9, 2013
    @serhiy-storchaka
    Copy link
    Member

    What type should be a result of slicing? List, tuple, deque, other?

    @larryhastings
    Copy link
    Contributor

    For the record, Raymond asked for permission to check this in (a new feature) for 3.5 beta 2, as he won't have time to finish it before beta 1. As 3.5 release manager I've given him permission. Go Raymond!

    @serhiy-storchaka
    Copy link
    Member

    Proposed patch implements getting, deleting and setting slices in deque.

    Getting a slice returns a list, but this can be changed if needed.

    @serhiy-storchaka
    Copy link
    Member

    Synchronized with current sources and added mandatory now braces.

    @rhettinger
    Copy link
    Contributor Author

    Thank you for doing this work.

    @MojoVampire
    Copy link
    Mannequin

    MojoVampire mannequin commented Jan 27, 2016

    It seems odd to have a slice of a deque return a list. Are there any other examples of non-buffer protocol objects behaving like this in the standard library/built-ins? Only examples I can come up with are mmap objects and ctypes arrays (which are making raw binary data available in Python); it seems rather surprising that a Python level type like deque would slice to produce a list.

    @rhettinger
    Copy link
    Contributor Author

    Returning a deque is preferred. For this stage, I just want to review the code and make sure it algorithmically correct (slicing is complicated and has a lot of cases).

    @serhiy-storchaka
    Copy link
    Member

    Since the patch is so complex, I suggest to split it on parts, and review and commit them separately:

    1. Refactoring. Extract common code to macros and utility functions. These macros can be used for more efficient implementing insert() and __del__.

    2. Add slice getting.

    3. Add slice assignment and deleting. I'm not sure that this is needed for deque.

    @rhettinger
    Copy link
    Contributor Author

    I'm already underway for the review. The "refactoring" part is making is more difficult. We just need slicing support to be added. Yes, I do want slice assignment and deletion. The output should be a deque, not a list.

    @serhiy-storchaka
    Copy link
    Member

    The output now is a deque.

    @serhiy-storchaka
    Copy link
    Member

    Raymond, do you have a time to make a review?

    @serhiy-storchaka
    Copy link
    Member

    Raymond, do you still have an interest in this issue? If no, you can just close it.

    @serhiy-storchaka
    Copy link
    Member

    Ping.

    @rhettinger
    Copy link
    Contributor Author

    If no, you can just close it.

    Yes, I would rather close this than apply this patch.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants