-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Optimize pathlib.PurePath.__fspath__() #102783
Copy link
Copy link
Closed as not planned
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
Done
Feature or enhancement
Return an unnormalized path from
pathlib.PurePath.__fspath__()Pitch
Code like
open(Path('./README.txt'))orPath('/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
Pathmethods, and the effective performance of passing aPathobject to any API that acceptsos.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
pathlib.PurePath.__fspath__()by returning raw path #112397