bpo-40563: Support pathlike objects on dbm/shelve#20274
Conversation
remilapeyre
left a comment
There was a problem hiding this comment.
Hi @hakancelik96, thanks for opening this PR!
There is some parts in dbm that were not updated:
>>> fn = pathlib.Path('foo')
>>> dbm.dumb.open(fn)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/remi/src/cpython/Lib/dbm/dumb.py", line 316, in open
return _Database(file, mode, flag=flag)
File "/Users/remi/src/cpython/Lib/dbm/dumb.py", line 57, in __init__
self._dirfile = filebasename + '.dir'
TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'
>>> dbm.gnu.open(fn)
Exception ignored in: <function _Database.close at 0x101c69370>
Traceback (most recent call last):
File "/Users/remi/src/cpython/Lib/dbm/dumb.py", line 274, in close
self._commit()
File "/Users/remi/src/cpython/Lib/dbm/dumb.py", line 116, in _commit
if self._index is None or not self._modified:
AttributeError: '_Database' object has no attribute '_index'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: open() argument 1 must be str, not PosixPath
>>> dbm.ndbm.open(fn)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: open() argument 1 must be str, not PosixPath
and I think the documentation also needs to be updated, see for example the note added to shutil.move() documentation when it was updated to support pathlib: #15326.
Thanks!
|
@remilapeyre thanks for your review, I will send a new commit when I solve these issues. |
|
Hi @hakancelik96, thanks for updating the rest of the module! It looks like there is some merge conflicts, could you fix these? I think running |
remilapeyre
left a comment
There was a problem hiding this comment.
There is some syntax errors, I'm not sure how the CI tests passed with them.
|
@remilapeyre Thanks for reviewing. I resolved syntax issues. |
|
Thanks for fixing the syntax issues @hakancelik96, please have a look at the compilation errors: |
|
I'll send a new PR with a clear history |
|
Don't worry too much about the history, everything will be squashed anyway and it's normal to write corrections for a PR. |
Any link to that PR? Or can you say if you are not working on it anymore? |
|
@audeoudh I am not working on anymore. |
|
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. |
https://bugs.python.org/issue40563