-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Comments
>>> 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 |
I work on this issue to fix it. |
Are you still working on this @hakancelik? |
Yes I will send pr soon. |
@DahlitzFlorian it looks like a PR was submitted August of last year : #21849 |
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 With my temporary debugging, I have this function in [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:
So before I get to the first line of the _gdbm.open() function, the TypeError is already occurring when passed a PosixPath. |
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. |
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. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: