Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
AlexWaygood merged 31 commits intopython:mainfrombarneygale:gh-101000-splitroot
Jan 27, 2023

Conversation

@barneygale
Copy link
Contributor

@barneygalebarneygale commentedJan 12, 2023
edited by bedevere-bot
Loading

This PR introducesos.path.splitroot(). See#101000 for motivation.

Inntpath, 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.

Inposixpath, thenormpath() function now callssplitroot() rather than parsing path roots itself.

Inpathlib, path constructors now callsplitroot() rather than using a slow OS-agnostic implementation. Performance:

$ ./python -m timeit -s'from pathlib import PureWindowsPath''PureWindowsPath("C:/", "foo", "bar")'50000 loops, best of 5: 6.04 usec per loop# before50000 loops, best of 5: 4.03 usec per loop# after$ ./python -m timeit -s'from pathlib import PurePosixPath''PurePosixPath("/", "etc", "hosts")'100000 loops, best of 5: 3.11 usec per loop# before100000 loops, best of 5: 2.77 usec per loop# after

Future work:

  • Improve performance by using nativent._path_splitroot()

@barneygalebarneygale marked this pull request as ready for reviewJanuary 12, 2023 22:57
Copy link
Contributor

@h-vetinarih-vetinari left a 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.

barneygale reacted with heart emoji
@barneygale
Copy link
ContributorAuthor

Drive-by comments from seeing this PR on discourse, feel free to disregard if I'm saying/asking something stupid.

Thanks for the review! All good feedback I think!

Copy link
Member

@AlexWaygoodAlexWaygood left a 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).

barneygale reacted with rocket emoji
@AlexWaygoodAlexWaygood self-requested a reviewJanuary 15, 2023 19:24
Co-authored-by: Eryk Sun <eryksun@gmail.com>
... and not belabour the fact that the empty string may be returned asany/all items.
Copy link
Member

@AlexWaygoodAlexWaygood left a comment
edited
Loading

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:

deftest_path_splitdrive(self):
self._check_function(self.path.splitdrive)

barneygale reacted with thumbs up emoji
@bedevere-bot
Copy link

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 phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Member

@AlexWaygoodAlexWaygood left a comment
edited
Loading

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.

# Issue #19911: UNC part containing U+0130
self.assertEqual(ntpath.splitdrive('//conky/MOUNTPOİNT/foo/bar'),
('//conky/MOUNTPOİNT','/foo/bar'))

and

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
Copy link
ContributorAuthor

Hm. I could renametest_splitdrive totest_splitroot and adjust all the test cases - would that address your concern? (I'd add a new set of tests forsplitdrive() that would cover just the basics)

@AlexWaygood
Copy link
Member

Hm. I could renametest_splitdrive totest_splitroot and adjust all the test cases - would that address your concern? (I'd add a new set of tests forsplitdrive() that would cover just the basics)

Yeah, I think that would make sense!

Copy link
Member

@AlexWaygoodAlexWaygood left a 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? :)

barneygale reacted with heart emoji
@AlexWaygoodAlexWaygood added type-featureA feature request or enhancement topic-pathlib labelsJan 23, 2023
@AlexWaygood
Copy link
Member

(Planning to merge in a few days, unless@eryksun has any further feedback :)

barneygale reacted with thumbs up emoji

@AlexWaygoodAlexWaygood merged commite5b08dd intopython:mainJan 27, 2023
mdboom pushed a commit to mdboom/cpython that referenced this pull requestJan 31, 2023
Co-authored-by: Eryk Sun <eryksun@gmail.com>Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@eryksuneryksuneryksun left review comments

@AlexWaygoodAlexWaygoodAlexWaygood approved these changes

+1 more reviewer

@h-vetinarih-vetinarih-vetinari left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

topic-pathlibtype-featureA feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@barneygale@bedevere-bot@AlexWaygood@eryksun@h-vetinari

[8]ページ先頭

©2009-2025 Movatter.jp