Uh oh!
There was an error while loading. Please reload this page.
GH-104996: Implement path joining algorithm in pathlib - #105484
GH-104996: Implement path joining algorithm in pathlib#105484barneygale wants to merge 3 commits into
Conversation
Copy the `ntpath.join()` algorithm into pathlib and adjust it to remove string concatenation. The resulting drive, root and tail are stored on the path object without creating an intermediate joined path.
barneygale
commented
Jul 24, 2023
@eryksun do you think you could you review this please? It's a variant of the |
eryksun
commented
Jul 24, 2023
I'm not thrilled about duplicating the code from defjoin(path, *paths):
paths= [os.fspath(path), *paths]
ifisinstance(paths[0], bytes):
path=b''sep=b'\\'seps=b'\\/'colon=b':'else:
path=''sep='\\'seps='\\/'colon=':'try:
drive, root, path_list=splitseq(paths)
forpinpath_list:
ifpathandpath[-1] notinseps:
path+=seppath+=p# If needed, add a separator between a UNC drive and path.ifpathandnotrootanddriveanddrive[-1:] !=colon:
returndrive+sep+pathreturndrive+root+pathexcept (TypeError, AttributeError, BytesWarning):
genericpath._check_arg_types('join', *paths)
raise |
barneygale
commented
Jul 26, 2023
The only problem I see there is that |
eryksun
commented
Jul 27, 2023
I think a better function name would help. Maybe
|
barneygale
commented
Jul 27, 2023
Maybe |
barneygale
commented
Nov 22, 2023
I'm withdrawing this PR as it bakes elements of pathlib's current normalisation logic into the path parsing/joining, and the overlap precludes user customisation and some other optimisations I have in mind. |
Copy the
ntpath.join()algorithm into pathlib and adjust it to remove string concatenation. The resulting drive, root and tail are stored on the path object without creating an intermediate joined path.Timings in microseconds:
PurePosixPath().rootPurePosixPath("/a").rootPurePosixPath("/a", "b").rootPurePosixPath("/a", "b", "c").rootPureWindowsPath().rootPureWindowsPath("/a").rootPureWindowsPath("/a", "b").rootPureWindowsPath("/a", "b", "c").root