Closed
Description
Feature or enhancement
Speed up os.path.splitroot()
by implementing it in C.
Pitch
I think
splitroot()
warrants a C implementation since it's a required step in our basic path handling on Windows --join()
,split()
,relpath()
, andcommonpath()
. Speeding it up gives a little boost across the board. Also, it would be less confusing ifnt._path_splitroot()
actually implementedntpath.splitroot()
.If implemented, using
_Py_splitroot()
in_Py_normpath()
would help to ensure consistency. Currently, for example,ntpath.normpath('//?/UNC/server/share/../..')
is correct on POSIX but wrong on Windows because_Py_normpath()
incorrectly handles "//?/UNC/" as the root instead of "//?/UNC/server/share/".
Previous discussion
- https://discuss.python.org/t/add-os-path-splitroot/22243
- Add os.path.splitroot() function #101000
- GH-80486: Fix handling of NTFS alternate data streams in pathlib #102454
Linked PRs
- gh-102511: Add C implementation of
os.path.splitroot()
#118089 - [3.12] gh-102511: Fix
os.path.normpath()
for UNC paths on Windows. #119394 - gh-102511: Amend 3.13.0b1.rst #119895
- [3.13] gh-102511: Amend 3.13.0b1.rst (GH-119895) #119980
- gh-102511: Change the
os.path.splitroot
param name frompath
back top
#124097 - [3.13] gh-102511: Change the
os.path.splitroot
param name frompath
back top
(GH-124097) #124919