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 shelve support dict union? #87609

Closed
Dominik1123 mannequin opened this issue Mar 9, 2021 · 10 comments
Closed

Should shelve support dict union? #87609

Dominik1123 mannequin opened this issue Mar 9, 2021 · 10 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Dominik1123
Copy link
Mannequin

Dominik1123 mannequin commented Mar 9, 2021

BPO 43443
Nosy @rhettinger, @ambv, @serhiy-storchaka, @miss-islington, @brandtbucher, @Dominik1123
PRs
  • bpo-43443: Clarify difference between shelve objects and dicts #27004
  • [3.10] bpo-43443: Clarify difference between shelve objects and dicts (GH-27004) #27369
  • [3.9] bpo-43443: Clarify difference between shelve objects and dicts (GH-27004) #27370
  • 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 2021-07-26.19:33:20.289>
    created_at = <Date 2021-03-09.08:46:35.421>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'Should shelve support dict union?'
    updated_at = <Date 2021-07-26.19:33:20.288>
    user = 'https://github.com/Dominik1123'

    bugs.python.org fields:

    activity = <Date 2021-07-26.19:33:20.288>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-26.19:33:20.289>
    closer = 'lukasz.langa'
    components = ['Library (Lib)']
    creation = <Date 2021-03-09.08:46:35.421>
    creator = 'Dominik V.'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43443
    keywords = ['patch']
    message_count = 10.0
    messages = ['388335', '388338', '388342', '388388', '388389', '388394', '388395', '398242', '398252', '398253']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'lukasz.langa', 'serhiy.storchaka', 'miss-islington', 'brandtbucher', 'Dominik V.']
    pr_nums = ['27004', '27369', '27370']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43443'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @Dominik1123
    Copy link
    Mannequin Author

    Dominik1123 mannequin commented Mar 9, 2021

    The docs of shelve mention that

    Shelf objects support all methods supported by dictionaries. This eases the transition from dictionary based scripts to those requiring persistent storage.

    However the |= operator is not implemented, preventing a seamless transition from dict to shelve. So should this be implemented for Shelf as well? | on the other hand doesn't make much sense.

    Otherwise the docs could be updated.

    @Dominik1123 Dominik1123 mannequin added 3.10 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 9, 2021
    @serhiy-storchaka
    Copy link
    Member

    The comment is outdated. Shelf objects also do not support methods copy and fromkey. Creating a new Shelve object without specifying a new underlying database object does not make much sense.

    Maybe say that they implement the MutableMapping interface?

    >>> sorted(set(dir(dict)) - set(dir(shelve.Shelf)))
    ['__ior__', '__or__', '__ror__', 'copy', 'fromkeys']
    >>> sorted(set(dir(collections.abc.MutableMapping)) - set(dir(shelve.Shelf)))
    []

    @Dominik1123
    Copy link
    Mannequin Author

    Dominik1123 mannequin commented Mar 9, 2021

    Right, that seems like a good idea. But __ior__ could be implemented nevertheless?

    @rhettinger
    Copy link
    Contributor

    Maybe say that they implement the MutableMapping interface?

    Yes, that's a good idea (also add link to the MutableMapping docs).

    Right, that seems like a good idea. But __ior__ could
    be implemented nevertheless?

    Off-hand, I don't see why not.

    Adding Brandt to the nosy list to see what he thinks.

    @rhettinger
    Copy link
    Contributor

    One other thought. While __ior__() could be used as a short-cut for update(), the related __or__() method is more problematic because it would need to create a new underlying DB. So maybe this is a can worms that we should not open. It would be weird to have __ior__() but not __or__().

    @brandtbucher
    Copy link
    Member

    +1 for the MutableMapping comment.

    We purposely omitted shelve when determining what classes should grow the new operators. Guido's thoughts:

    I definitely think we should leave Shelf alone, it's a toy class from a different era.

    (https://bugs.python.org/msg364196)

    I personally have no experience with shelve, so I'd rather defer to the judgement of others here.

    @Dominik1123
    Copy link
    Mannequin Author

    Dominik1123 mannequin commented Mar 9, 2021

    It's true, having __ior__ but not __or__ would probably be weird. In the end it's just "nice to have", but I'm not even sure that this applies. Calling db.update(...) is still more explicit than db |= .... The docs mention that

    This eases the transition from dictionary based scripts to those requiring persistent storage.

    For my use cases, however, I always knew right from the beginning that I want object persistence between different runs of a script (e.g. for data analysis, caching the expensive results), so it was always clear that I'm working with a Shelf object and not a dict (i.e. no expectations on the availability of |=).

    Primarily, this issue was meant to point out the mismatch of docs/implementation and not to get |= implemented for Shelf. In the end, I think updating the docs is all that is needed.

    @ambv
    Copy link
    Contributor

    ambv commented Jul 26, 2021

    New changeset c97c2a0 by Serhiy Storchaka in branch 'main':
    bpo-43443: Clarify difference between shelve objects and dicts (GH-27004)
    c97c2a0

    @ambv
    Copy link
    Contributor

    ambv commented Jul 26, 2021

    New changeset 563e057 by Miss Islington (bot) in branch '3.10':
    bpo-43443: Clarify difference between shelve objects and dicts (GH-27004) (GH-27369)
    563e057

    @ambv
    Copy link
    Contributor

    ambv commented Jul 26, 2021

    New changeset 7482fff by Miss Islington (bot) in branch '3.9':
    bpo-43443: Clarify difference between shelve objects and dicts (GH-27004) (GH-27370)
    7482fff

    @ambv ambv added the 3.11 only security fixes label Jul 26, 2021
    @ambv ambv closed this as completed Jul 26, 2021
    @ambv ambv added the 3.11 only security fixes label Jul 26, 2021
    @ambv ambv closed this as completed Jul 26, 2021
    @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.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants