Skip to content

new feature: Python should accept Path for root argument #6479

@jayceslesar

Description

@jayceslesar

Feature Description

The following fails:

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 '<unnamed>' panicked at src/operator.rs:76:22:
must be valid hashmap: PyErr { type: <class 'TypeError'>, 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 <module>
    op = Operator("fs", root=Path("foo").resolve())
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyo3_runtime.PanicException: must be valid hashmap: PyErr { type: <class 'TypeError'>, 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?

  • Yes, I am willing to contribute to the development of this feature.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions