Skip to content

Add pathlib.Path.from_uri() classmethod #107465

Closed
@barneygale

Description

@barneygale

Feature or enhancement

Add pathlib.Path.from_uri() classmethod that creates a path objects from a 'file' URI, like file:///c:/windows. This method should accept RFC 8089 file: URIs, including variant forms.

Pitch

The proposed method is the counterpart of pathlib.Path.as_uri(). As we continue to open up pathlib for subclassing, user subclasses of path classes will begin to appear with their own as_uri() methods returning URIs like s3://, ftp://. These subclasses will likely also support parsing URIs to create paths. However, there is currently no defined interface for doing this in pathlib, and users will be tempted to accept URIs in initialisers, which produces a confusing interface. If pathlib instead defines a from_uri() classmethod, there is one clear and obvious method that subclasses may override.

Previous discussion

See https://discuss.python.org/t/make-pathlib-extensible/3428/136 and subsequent posts

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions