Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-101000: Add os.path.splitroot()#101002
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
h-vetinari left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Drive-by comments from seeing this PR on discourse, feel free to disregard if I'm saying/asking something stupid.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
barneygale commentedJan 13, 2023
Thanks for the review! All good feedback I think! |
Uh oh!
There was an error while loading.Please reload this page.
AlexWaygood left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm persuaded that this is a good idea. Thanks for working on this!
Here's a docs review. Haven't got to looking at the implementation yet (will do soon).
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Eryk Sun <eryksun@gmail.com>
... and not belabour the fact that the empty string may be returned asany/all items.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
AlexWaygood left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I believe there are currently no tests thatos.path.splitroot works withos.PathLike objects. Just trivial tests like this should do fine, but we should make sure it's tested:
cpython/Lib/test/test_ntpath.py
Lines 946 to 947 in0e75a55
| deftest_path_splitdrive(self): | |
| self._check_function(self.path.splitdrive) |
bedevere-bot commentedJan 22, 2023
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Misc/NEWS.d/next/Library/2023-01-12-21-22-20.gh-issue-101000.wz4Xgc.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
AlexWaygood left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is looking really good to me now, and I'm very close to hitting "approve". My only concern (other than my comment about the NEWS entry) is that I'm still not sure the test coverage is quite there. It looks like the tests forsplitdrive() account for a lot of edge cases that aren't really tackled in the tests forsplitroot() yet, e.g.
cpython/Lib/test/test_ntpath.py
Lines 117 to 119 ine99e3cd
| # Issue #19911: UNC part containing U+0130 | |
| self.assertEqual(ntpath.splitdrive('//conky/MOUNTPOİNT/foo/bar'), | |
| ('//conky/MOUNTPOİNT','/foo/bar')) |
and
cpython/Lib/test/test_ntpath.py
Lines 129 to 130 ine99e3cd
| tester('ntpath.splitdrive("//?/VOLUME{00000000-0000-0000-0000-000000000000}/spam")', | |
| ('//?/VOLUME{00000000-0000-0000-0000-000000000000}','/spam')) |
It's true that, sincesplitdrive() now usessplitroot(), these edge cases are in some sense already covered -- the tests forsplitdrive() will start failing if a bug is introduced tosplitroot() at some later date in the future. But it will be highly confusing if the tests forsplitdrive() start failing, yet the tests forsplitroot() all still pass, when the bug is actually in the implementation forsplitroot().
barneygale commentedJan 22, 2023
Hm. I could rename |
AlexWaygood commentedJan 22, 2023
Yeah, I think that would make sense! |
AlexWaygood left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks great to me. Thanks, as ever, for your patience and perseverance!
@eryksun, Any further comments from you? :)
AlexWaygood commentedJan 24, 2023
(Planning to merge in a few days, unless@eryksun has any further feedback :) |
Co-authored-by: Eryk Sun <eryksun@gmail.com>Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Uh oh!
There was an error while loading.Please reload this page.
This PR introduces
os.path.splitroot(). See#101000 for motivation.In
ntpath, the implementation derives fromsplitdrive(). Thesplitdrive()function now callssplitroot(), and returnsdrive, root + tail. Other functions now callsplitroot()rather thansplitdrive(). In most cases this replaces their own parsing of path roots. It also avoids adding a stack frame.In
posixpath, thenormpath()function now callssplitroot()rather than parsing path roots itself.In
pathlib, path constructors now callsplitroot()rather than using a slow OS-agnostic implementation. Performance:Future work:
nt._path_splitroot()