Skip to content

Support converting std::path::{Path, PathBuf} to pathlib.Path #4907

Open
@Ravencentric

Description

For example, take this very simple rust function. Calling it from python will result in PathBuf getting converted to builtins.str instead of pathlib.Path. My feature request is that it should instead convert to pathlib.Path.

fn get_parent_directory(path: PathBuf) -> PyResult<PathBuf> {
    let dir = match path.as_ref().parent() {
        Some(parent) if parent == Path::new("") => Path::new("."),
        Some(parent) => parent,
        None => Path::new("."),
        };

    let dir = dunce::canonicalize(dir).map_err(|e| PyOSError::new_err(e.to_string()))?;
    Ok(dir)
}

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions