Skip to content

Add a module with an OsPath-typed API #197

@carlwr

Description

@carlwr

When importing paths OsPath module, we get either the PosixPath- or WindowsPath-typed API, depending on our platform. This means that for interactions between our user code and functions of path, in order to write portable code, we need to write code handling both PosixPath and WindowsPath (or a wrapper that translates platform-dependently at compile-time).

But typically nowadays, to write portable code, we prefer using an OsPath-typed interfaces everywhere - which does the right thing under-the-hood regardless of what platform we are compiling on. But path currently doesn't expose such an interface.

Is there a fundamental reason why not? I read through the PR introducing the OsPath module, but couldn't find anything there.

Otherwise I'd suggest adding a module with OsPath-typed functions, e.g. as OsPath.OsPath:

# modules of `path`:

OsPath            # type: PosixPath/WindowsPath
OsPath.OsPath     # type: OsPath                 <-- NEW - SUGGESTION
OsPath.Posix      # type: PosixPath
OsPath.Windows    # type: WindowsPath
Path
# ...

It could be useful to study e.g. file-io, directory-ospath-streaming as examples of other packages that include an OsPath-typed API (and of course e.g. filepath, directory).

The implementation should be thin. I'm happy to provide a PR if of interest.

Gently pinging @hasufell who might have opinions around this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions