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

Support pathlike objects on dbm/shelve #84743

Closed
isidentical opened this issue May 8, 2020 · 9 comments
Closed

Support pathlike objects on dbm/shelve #84743

isidentical opened this issue May 8, 2020 · 9 comments
Labels
3.11 only security fixes easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@isidentical
Copy link
Sponsor Member

BPO 40563
Nosy @ethanfurman, @serhiy-storchaka, @DavidMertz, @DahlitzFlorian, @isidentical, @hakancelik96, @Dreamsorcerer
PRs
  • bpo-40563: Support pathlike objects on dbm/shelve #20274
  • bpo-40563: Support pathlike objects on dbm/shelve #21849
  • 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-09-10.12:38:18.317>
    created_at = <Date 2020-05-08.14:55:55.521>
    labels = ['easy', 'type-feature', 'library', '3.11']
    title = 'Support pathlike objects on dbm/shelve'
    updated_at = <Date 2021-09-10.12:38:18.316>
    user = 'https://github.com/isidentical'

    bugs.python.org fields:

    activity = <Date 2021-09-10.12:38:18.316>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-09-10.12:38:18.317>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2020-05-08.14:55:55.521>
    creator = 'BTaskaya'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40563
    keywords = ['patch', 'easy']
    message_count = 9.0
    messages = ['368446', '368447', '369471', '369478', '401348', '401430', '401431', '401575', '401576']
    nosy_count = 9.0
    nosy_names = ['ethan.furman', 'python-dev', 'serhiy.storchaka', 'gene_wood', 'DavidMertz', 'DahlitzFlorian', 'BTaskaya', 'hakancelik', 'dreamsorcerer']
    pr_nums = ['20274', '21849']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue40563'
    versions = ['Python 3.11']

    @isidentical
    Copy link
    Sponsor Member Author

    >>> dbm.open("/tmp/x.db", "n").close()
    >>> from pathlib import Path
    >>> tmp = Path("/tmp")
    >>> dbm.open(tmp / "x.db", "n").close()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.9/dbm/__init__.py", line 95, in open
        return mod.open(file, flag, mode)
    TypeError: open() argument 1 must be str, not PosixPath

    @isidentical isidentical added 3.9 only security fixes stdlib Python modules in the Lib dir easy labels May 8, 2020
    @hakancelik96
    Copy link
    Mannequin

    hakancelik96 mannequin commented May 8, 2020

    I work on this issue to fix it.

    @DahlitzFlorian
    Copy link
    Mannequin

    DahlitzFlorian mannequin commented May 20, 2020

    Are you still working on this @hakancelik?

    @hakancelik96
    Copy link
    Mannequin

    hakancelik96 mannequin commented May 20, 2020

    Yes I will send pr soon.

    @genewood
    Copy link
    Mannequin

    genewood mannequin commented Sep 7, 2021

    @DahlitzFlorian it looks like a PR was submitted August of last year : #21849

    @DavidMertz
    Copy link
    Mannequin

    DavidMertz mannequin commented Sep 9, 2021

    I've made the few additional changes to those in this PR. When I work out the issues, I'll make a new PR. I took out an attempt with path_t. However, here is why I think argument clinic (or something else?!) is actually intercepting the attempted call:

    With my temporary debugging, I have this function in [Modules/_gdbmmodule.c](https://github.com/python/cpython/blob/main/Modules/_gdbmmodule.c):

    [clinic start generated code]*/
    
    static PyObject *
    dbmopen_impl(PyObject *module, PyObject *filename, const char *flags,
                 int mode)
    /*[clinic end generated code: output=9527750f5df90764 input=812b7d74399ceb0e]*/
    {
        PyObject_Print(filename, stdout, 0);
        printf(" from _gdbmmodule.c (XXX)\n");
        /* ... rest of function ...*/

    And I have a very simplified test script:

    import _gdbm
    import sys
    from pathlib import Path
    
    print(sys.version)
    path = '/tmp/tmp.db'
    
    db = _gdbm.open(path, 'c')
    print("Opened with string path")
    db.close()
    
    db = _gdbm.open(Path(path), 'c')
    print("Opened with path-like")
    db.close()

    The output of running this is:

    3.11.0a0 (heads/[bpo-45133](https://bugs.python.org/issue45133)-dirty:0376feb030, Sep  8 2021, 00:39:39) [GCC 10.3.0]
    '/tmp/tmp.db' from _gdbmmodule.c (XXX)
    Opened with string path
    Traceback (most recent call last):
      File "/home/dmertz/tmp/pathlike-dbm.py", line 12, in <module>
        db = _gdbm.open(Path(path), 'c')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: open() argument 1 must be str, not PosixPath
    

    So before I get to the first line of the _gdbm.open() function, the TypeError is already occurring when passed a PosixPath.

    @DavidMertz DavidMertz mannequin added 3.11 only security fixes type-feature A feature request or enhancement and removed 3.9 only security fixes labels Sep 9, 2021
    @DavidMertz
    Copy link
    Mannequin

    DavidMertz mannequin commented Sep 9, 2021

    If anyone wants to look at my not-yet-complete changes (see other comment), it's https://github.com/DavidMertz/cpython/tree/bpo-45133. It has a different bpo because I filed a duplicate before realizing. I can change the branch name before a PR, but making it work is the more important issue.

    @serhiy-storchaka
    Copy link
    Member

    New changeset 707137b by Henry-Joseph Audéoud in branch 'main':
    bpo-40563: Support pathlike objects on dbm/shelve (GH-21849)
    707137b

    @serhiy-storchaka
    Copy link
    Member

    Thank you for your contribution, Hakan, Henry-Joseph.

    Sorry, David, there was already a PR, and it was not dead, it just waited for a coredev review.

    @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.11 only security fixes easy 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