Skip to content

pathlib.PurePath.as_uri() and __bytes__() are impure #100415

Closed as not planned
Closed as not planned
@barneygale

Description

@barneygale

pathlib.PurePath.as_uri() and __bytes__() use os.fsencode() to encode paths, which makes their results vary from system to system. In pathlib parlance these methods are "impure", and so they rightfully belong to the Path class, not the PurePath class.

Furthermore, the as_uri() method may confuse users if we add an AbstractPath class that sits between PurePath and Path, as the default implementation would provide a file:// URI in a naive user subclass such as S3Path or FTPPath. I think this helps demonstrate that file:// URIs really are a local filesystem feature, and so should not be implemented in PurePath.

Proposal: emit deprecation warnings from as_uri() and __bytes__() unless isinstance(self, Path). In a future version of Python, move the implementations into Path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions