-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Add os.path.splitroot() function #101000
Labels
3.12
bugs and security fixes
stdlib
Python modules in the Lib dir
topic-pathlib
type-feature
A feature request or enhancement
Comments
barneygale
added a commit
to barneygale/cpython
that referenced
this issue
Jan 12, 2023
eryksun
added
stdlib
Python modules in the Lib dir
3.12
bugs and security fixes
topic-pathlib
labels
Jan 13, 2023
AlexWaygood
added a commit
to barneygale/cpython
that referenced
this issue
Jan 22, 2023
AlexWaygood
added a commit
that referenced
this issue
Jan 27, 2023
Co-authored-by: Eryk Sun <eryksun@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Added in #101002. Thanks @barneygale 🎉🥳 |
Thank you very much Alex! \o/ |
mdboom
pushed a commit
to mdboom/cpython
that referenced
this issue
Jan 31, 2023
Co-authored-by: Eryk Sun <eryksun@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
3.12
bugs and security fixes
stdlib
Python modules in the Lib dir
topic-pathlib
type-feature
A 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 + tail
is 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 + root
as 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 intontpath
andposixpath
we can take advantage of OS-specific rules to improve pathlib performance.Previous discussion
Linked PRs
The text was updated successfully, but these errors were encountered: