I attempted to do this today, as my first actual contribution to CPython itself. I think the prior attempt went down a wrong path, which is why neither PR could actually pass tests.
I've been looking at `posixmodule.c` for comparison, specifically. The key thing, I believe, is not to use `PyObject *filename` in the `dpmopen_impl()` calls at all, but rather `path_t *path`. I tried some absolutely crude instrumentation to see why the `PyOS_FSPath` macro and the rest wasn't doing what it seems like it should (i.e. sticking `printf()`s in the .c files). Eventually I realized that argument clinic is stopping me from even getting to the body of the function when `filename` was a PosixPath, so anything that PyOS_FSPath does is moot.
I think in the end the new code should be even simpler than the main (3.11) branch. All I really need to do with a `path_t` is be able to call:
PyObject *self = newgdbmobject(state, name, iflags, mode);
That is, `name` is simply the filename as char* (the other parameters are independent of the path-like issue).
Does anyone have pointers to an example or documentation about doing this? The patterns in posixmodule.c are suggestive, but I'm not sure of the missing pieces.
Also, I copied the typedef for path_t from posixmodule.c to both `_dbmmodule.c` and `_gdbmmodule.c`. I know that's also going to be wrong, and it should be pulled into an .h file. Any idea about which one? `posixmodule.h` seems like a possibility, but then I'd need to repeat it in `winreparse.h`. Maybe a new name?
If someone posted a Pull Request that added this, it would be looked upon favorably I'm sure.
it looks like this as had a BPO for over a year:
I suggest pinging that (and maybe python-dev) to see what's up.
NOTE: first check 3.10 :-)
-CHB
Currently, in Python 3.9, `dbm.open()`, `dbm.gnu.open()` and `dbm.ndbm.open()` doesn't support path-like object, class defined in `pathlib`.
It would be nice to add support with it.