-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Add os.path.splitroot() function #101000
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixesstdlibStandard 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
3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement
Feature or enhancement
Add a function that splits a path into a
(drive, root, tail)triad:splitdrive()Similarly to
splitdrive(), asplitroot()function would ensure thatdrive + root + tailis the same as the input path.Pitch
The extra level of detail reflects an extra step in the Windows 'current path' hierarchy -- Windows has both a 'current drive', and a 'current directory' for one or more drives, which results in several kinds of non-absolute paths, e.g. 'foo/bar', '/foo/bar', 'X:foo/bar'
This three-part model is used successfully by pathlib, which exposes root as an attribute, and combines
drive + rootas an attribute called anchor. The anchor has useful properties, e.g. comparing two paths anchors can tell us whether arelative_to()operation is possible.Pathlib has its own implementation of
splitroot(), but its performance is hamstrung by its need for OS-agnosticism. By moving the implementation intontpathandposixpathwe can take advantage of OS-specific rules to improve pathlib performance.Previous discussion
Linked PRs