new feature: Python should accept `Path` for `root` argument
- Dominant language
- Rust
- Stars
- 5.4k
- Forks
- 825
- Avg merge
- 1d 14m
- Merged PRs (30d)
- 127
Description
### Feature Description
The following fails:
```py
from opendal import Operator
from pathlib import Path
import os
os.makedirs("foo", exist_ok=True)
file = Path("foo", "bar.txt")
file.touch()
file.write_text("baz")
op = Operator("fs", root=Path("foo").resolve())
for file in op.list("/"):
print(file.metadata)
```
with:
```
thread '' panicked at src/operator.rs:76:22:
must be valid hashmap: PyErr { type: , value: TypeError("'PosixPath' object cannot be converted to 'PyString'"), traceback: None }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
File "/Users/jayceslesar/projects/fileparty/asdf.py", line 13, in
op = Operator("fs", root=Path("foo").resolve())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyo3_runtime.PanicException: must be valid hashmap: PyErr { type: , value: TypeError("'PosixPath' object cannot be converted to 'PyString'"), traceback: None }
```
### Problem and Solution
All other `PathBuf` arguments take `Path` objects so IMO it makes sense for `root` to also accept one.
### Additional Context
Simply wrapping the `Path` object in a `str` call works, as does calling `.name` but it makes sense to allow a `Path` object
### Are you willing to contribute to the development of this feature?
- [x] Yes, I am willing to contribute to the development of this feature.
Contributor guide
Assessment
This issue has not been assessed yet.