Skip to content

Optimize pathlib.PurePath.__fspath__() #102783

Closed as not planned
Closed as not planned
@barneygale

Description

@barneygale

Feature or enhancement

Return an unnormalized path from pathlib.PurePath.__fspath__()

Pitch

Code like open(Path('./README.txt')) or Path('/home//barney').iterdir() shouldn't require us to normalize the path in pathlib (e.g. remove . segments, doubled slashes, etc), as OS APIs are perfectly happy with unnormalized paths.

We can improve the performance of most Path methods, and the effective performance of passing a Path object to any API that accepts os.PathLike, by skipping normalization in __fspath__().

Prerequisites

Pathlib must not normalize paths on construction:

Pathlib's normalization must not change the meaning of paths:

Previous discussion

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibPython modules in the Lib dirtopic-pathlibtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions