Skip to content

Optimize pathlib.PurePath.__fspath__() #102783

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy