-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize pathlib.PurePath.__fspath__()
#102783
Comments
On Windows, an exception should be made to normalize extended paths in Scripts have to be prepared to handle extended paths coming from For path construction, there's an open issue that proposes to modify |
I don't think pathlib's normalization should change the meaning of paths. It sounds like we should adjust the normalization routine to preserve forward slashes, repeated slashes, and "." components, for these kinds of path. ".." components are already be preserved I think. |
In almost all cases, extended paths are used solely to access a long path. The need to get a literal path is rare, especially in regard to slashes and "." and ".." component names. Microsoft's filesystems will fail an open that has forward slashes or repeated backslashes. NTFS will fail an open that has "." or ".." component names. FAT filesystems allow creating "." and ".." component names as a file's long name, with some other random short name, but it's very dysfunctional. People assume that |
What happens if a path is mounted on e.g. a FUSE filesystem or a Samba share? Does the OS unnormalize before handing the path to the filesystem? |
…g raw path Return an unnormalized path from `pathlib.PurePath.__fspath__()`. This is equivalent to a normalized path (because pathlib's normalization doesn't change the meaning of paths), but considerably cheaper to generate.
Resolving as "can't do", because #65238 is resolved as "won't fix" |
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
Path
methods, and the effective performance of passing aPath
object 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 #112397The text was updated successfully, but these errors were encountered: