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

Should MutableSequence provide .copy()? #77700

Closed
JelleZijlstra opened this issue May 15, 2018 · 7 comments
Closed

Should MutableSequence provide .copy()? #77700

JelleZijlstra opened this issue May 15, 2018 · 7 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@JelleZijlstra
Copy link
Member

BPO 33519
Nosy @rhettinger, @bitdancer, @serhiy-storchaka, @JelleZijlstra, @csabella
PRs
  • bpo-33519: clarify that .copy() is not part of the MutableSequence ABC #6965
  • 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 2019-05-19.00:18:57.446>
    created_at = <Date 2018-05-15.15:09:27.670>
    labels = ['3.8', 'type-feature', 'library']
    title = 'Should MutableSequence provide .copy()?'
    updated_at = <Date 2019-05-19.00:18:57.446>
    user = 'https://github.com/JelleZijlstra'

    bugs.python.org fields:

    activity = <Date 2019-05-19.00:18:57.446>
    actor = 'cheryl.sabella'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-19.00:18:57.446>
    closer = 'cheryl.sabella'
    components = ['Library (Lib)']
    creation = <Date 2018-05-15.15:09:27.670>
    creator = 'JelleZijlstra'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33519
    keywords = ['patch']
    message_count = 7.0
    messages = ['316664', '316672', '316673', '316697', '316744', '316749', '342826']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'stutzbach', 'r.david.murray', 'serhiy.storchaka', 'JelleZijlstra', 'cheryl.sabella']
    pr_nums = ['6965']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue33519'
    versions = ['Python 3.8']

    @JelleZijlstra
    Copy link
    Member Author

    https://docs.python.org/3.7/library/stdtypes.html#mutable-sequence-types lists .copy() among the methods provided by mutable sequences. However, MutableSequence does not actually define .copy(): https://github.com/python/cpython/blob/master/Lib/_collections_abc.py#L945.

    Should we add .copy() to the ABC or remove the promise that all mutable sequences implement .copy()?

    @JelleZijlstra JelleZijlstra added 3.8 only security fixes stdlib Python modules in the Lib dir labels May 15, 2018
    @bitdancer
    Copy link
    Member

    The ABCs are different from the standard types provided by python itself. The former are a minimal subset of the methods provided by the latter. So I think the answer is neither.

    @bitdancer
    Copy link
    Member

    On the other hand, that section does reference the ABC directly, so I can see the point of your question. So I guess I'm not sure what the answer is...I don't think copy is an essential part of the ABC, but I'm not sure.

    @serhiy-storchaka
    Copy link
    Member

    MutableSequence defines an interface. Adding a new method will break all classes that implemented this protocol but not the new method.

    And what should .copy() return? list subclasses return an exact list, bytearray subclasses return an exact bytearray, but deque subclasses try to create an instance of the same type. Not all mutable sequences can be copyable. The constructor is not the part of the protocol.

    The same problems are in MutableSet and MutableMapping. This is why they don't provide copy() methods (but concrete classes set and dict do).

    @rhettinger
    Copy link
    Contributor

    Should we add .copy() to the ABC or remove the promise that all mutable sequences implement .copy()?

    The second option would be best. Let's just clarify that copy() isn't part of the MutableSequence API.

    The first option isn't really a choice be it would break existing uses that don't implement copy and because the ABC have a reliable way to create a new instance using the given abstract methods (it has no way of even knowing whether the data is stored locally, in a database, or updated through a REST API, it may not even be possible to reliably create an independent instance).

    @JelleZijlstra
    Copy link
    Member Author

    Makes sense. I can provide a patch to the docs.

    @csabella
    Copy link
    Contributor

    New changeset 9892f45 by Cheryl Sabella (Jelle Zijlstra) in branch 'master':
    bpo-33519: clarify that .copy() is not part of the MutableSequence ABC (GH-6965)
    9892f45

    @csabella csabella added the type-feature A feature request or enhancement label May 19, 2019
    @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
    3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants