apache / apache/opendal

new feature: Python should accept `Path` for `root` argument

Open
#6,479 3 comments 1 reaction 1 assignee Claimed by @asukaminato0721 View on GitHub
bindings/python enhancement releases-note/feat services/fs
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.