René's URL Explorer Experiment


Title: gh-101000: Add os.path.splitroot() by barneygale · Pull Request #101002 · python/cpython · GitHub

Open Graph Title: gh-101000: Add os.path.splitroot() by barneygale · Pull Request #101002 · python/cpython

X Title: gh-101000: Add os.path.splitroot() by barneygale · Pull Request #101002 · python/cpython

Description: This PR introduces os.path.splitroot(). See #101000 for motivation. In ntpath, the implementation derives from splitdrive(). The splitdrive() function now calls splitroot(), and returns drive, root + tail. Other functions now call splitroot() rather than splitdrive(). In most cases this replaces their own parsing of path roots. It also avoids adding a stack frame. In posixpath, the normpath() function now calls splitroot() rather than parsing path roots itself. In pathlib, path constructors now call splitroot() 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 # before 50000 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 # before 100000 loops, best of 5: 2.77 usec per loop # after Future work: Improve performance by using native nt._path_splitroot() Issue: gh-101000

Open Graph Description: This PR introduces os.path.splitroot(). See #101000 for motivation. In ntpath, the implementation derives from splitdrive(). The splitdrive() function now calls splitroot(), and returns drive, root...

X Description: This PR introduces os.path.splitroot(). See #101000 for motivation. In ntpath, the implementation derives from splitdrive(). The splitdrive() function now calls splitroot(), and returns drive, root...

Opengraph URL: https://github.com/python/cpython/pull/101002

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/commits/:range(.:format)
route-controllerpull_requests
route-actioncommits
fetch-noncev2:06bd0f1f-e147-16c5-c678-440b0407c15c
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idC46C:C4DD7:664923F:8C9E9AA:699636EE
html-safe-noncee3d0ee69ad17835a8dadc0b5e6df5c585708df81ebc1b1639c4ade469661d6b4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDZDOkM0REQ3OjY2NDkyM0Y6OEM5RTlBQTo2OTk2MzZFRSIsInZpc2l0b3JfaWQiOiI4MDMxMTM4NTM1MTUwMzM1NzI2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac7936fb8a521cd4d3de6c511cfb2b1e46cce6b976afa223484784b3a0b66775d3
hovercard-subject-tagpull_request:1195923725
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/commits
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
twitter:imagehttps://avatars.githubusercontent.com/u/960340?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/960340?s=400&v=4
og:image:altThis PR introduces os.path.splitroot(). See #101000 for motivation. In ntpath, the implementation derives from splitdrive(). The splitdrive() function now calls splitroot(), and returns drive, root...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None979c1ab77a40e0dbb8d76f1c427190824693a0e72e7a954636654843f3881905
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release999924f6ca451247a9a3a0ef516776ac16e7135f
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F101002%2Fcommits%2F2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F101002%2Fcommits%2F2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Fcommits&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Reloadhttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Reloadhttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 34.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.6k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
AlexWaygoodhttps://github.com/AlexWaygood
python:mainhttps://github.com/python/cpython/tree/main
barneygale:gh-101000-splitroothttps://github.com/barneygale/cpython/tree/gh-101000-splitroot
Conversation 84 https://github.com/python/cpython/pull/101002
Commits 31 https://github.com/python/cpython/pull/101002/commits
Checks 0 https://github.com/python/cpython/pull/101002/checks
Files changed https://github.com/python/cpython/pull/101002/files
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
gh-101000: Add os.path.splitroot() https://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38#top
Show all changes 31 commits https://github.com/python/cpython/pull/101002/files
21c0ba9 gh-101000: Add os.path.splitroot() barneygale Jan 12, 2023 https://github.com/python/cpython/pull/101002/commits/21c0ba9069f496912f6cc6fc31f21055b772d1ea
836b85d Use splitroot() from pathlib barneygale Jan 12, 2023 https://github.com/python/cpython/pull/101002/commits/836b85d887b807bebfdb88f8443a6785e9005dec
bc2d1f9 Use splitroot() from posixpath barneygale Jan 12, 2023 https://github.com/python/cpython/pull/101002/commits/bc2d1f976fa07f092db018edcb398776fbc8a17f
ecdc40d Use splitroot() from ntpath barneygale Jan 12, 2023 https://github.com/python/cpython/pull/101002/commits/ecdc40dc94341feb080bbc5a5e424c930f7faef8
6592b27 Optimizations barneygale Jan 12, 2023 https://github.com/python/cpython/pull/101002/commits/6592b27e1d72516c47713ba508359445fe63e2c2
78f4227 Correct and expand examples in splitroot() docstring barneygale Jan 13, 2023 https://github.com/python/cpython/pull/101002/commits/78f42270b78e44c17d6d387bf9c083e2ba3938ea
9726ca4 Update Lib/ntpath.py barneygale Jan 13, 2023 https://github.com/python/cpython/pull/101002/commits/9726ca4e394947fa322a659593a9f252fe4a9c29
7a6613c Use splitroot() from pathlib.PurePath.with_name() barneygale Jan 14, 2023 https://github.com/python/cpython/pull/101002/commits/7a6613c5dc53391690102e2725cb93791a11007d
26a8dba Reduce ntpath.normpath() diff noise barneygale Jan 15, 2023 https://github.com/python/cpython/pull/101002/commits/26a8dba786c660cb97a112b44d56b42e7414f48d
0c237d4 Simplify ntpath.commonpath() now that 'isabs' is unused. barneygale Jan 15, 2023 https://github.com/python/cpython/pull/101002/commits/0c237d490b2a77759a9813e3b8433f6987b620a8
11ed3eb Reduce posixpath.normpath() diff noise barneygale Jan 15, 2023 https://github.com/python/cpython/pull/101002/commits/11ed3eb55a93fb21bc89ad6a27c7366dab20f0bf
2c9eed8 Improve documentation barneygale Jan 15, 2023 https://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
8299e96 Add whatsnew entry. barneygale Jan 15, 2023 https://github.com/python/cpython/pull/101002/commits/8299e969d316a9cd2b391c88cf203f1fa518ddd4
27ffe37 Simplify ntpath.splitroot() slightly barneygale Jan 15, 2023 https://github.com/python/cpython/pull/101002/commits/27ffe37a991ab0a2c8e25b5bfc72630026f2c37c
9beff2a Apply suggestions from code review barneygale Jan 16, 2023 https://github.com/python/cpython/pull/101002/commits/9beff2af6f5c80945fc745cc64ec9912c87b59a2
bacdee1 Update Doc/library/os.path.rst barneygale Jan 16, 2023 https://github.com/python/cpython/pull/101002/commits/bacdee153c5f28413f21c68ca7919d7311340e7b
4ebe545 Note that drive may be empty on Windows barneygale Jan 16, 2023 https://github.com/python/cpython/pull/101002/commits/4ebe54555959283b243ebce697c76ef988a57cfb
2927afe Re-order drive example barneygale Jan 16, 2023 https://github.com/python/cpython/pull/101002/commits/2927afe301417f7a53442416b73b34c45035e371
b0aa73e Update Doc/library/os.path.rst barneygale Jan 16, 2023 https://github.com/python/cpython/pull/101002/commits/b0aa73e41c782a5a4f0008d6cd8f8c2972afc499
19777d6 Adjust docstring examples barneygale Jan 18, 2023 https://github.com/python/cpython/pull/101002/commits/19777d65c409ae85d60c01d27b5a293dc6e5c605
32e212e Apply suggestions from code review barneygale Jan 19, 2023 https://github.com/python/cpython/pull/101002/commits/32e212e1cb08a6d2bf3704075b5d78a72b05b134
37cded3 Update Doc/library/os.path.rst barneygale Jan 19, 2023 https://github.com/python/cpython/pull/101002/commits/37cded31033f0314ee35e90b65794b19d30d8907
5a8dfce Change example username in docs to 'Sam' barneygale Jan 19, 2023 https://github.com/python/cpython/pull/101002/commits/5a8dfce4e15db8cac619637ec2344134547fc540
0e75a55 Adjust first paragraph to use prose barneygale Jan 19, 2023 https://github.com/python/cpython/pull/101002/commits/0e75a55b3f696e4481a51c7e414503aecf85caba
3663237 Update Doc/library/os.path.rst barneygale Jan 22, 2023 https://github.com/python/cpython/pull/101002/commits/36632370006d68e1bf5c67232f7b615e86b0b2aa
053729d Add tests for bytes (POSIX only) and path-like objects (both platforms) barneygale Jan 22, 2023 https://github.com/python/cpython/pull/101002/commits/053729debe973546048b65e360203937ab752e66
694f093 Add tests for mixed path separators (Windows only) barneygale Jan 22, 2023 https://github.com/python/cpython/pull/101002/commits/694f093fb62074ff7e34d54182fa06edd3c606ca
e99e3cd Remove errant newline. barneygale Jan 22, 2023 https://github.com/python/cpython/pull/101002/commits/e99e3cd2262918ee4148258f3f49360ee85850f2
f618a00 Move most test cases from `test_splitdrive` to `test_splitroot` barneygale Jan 22, 2023 https://github.com/python/cpython/pull/101002/commits/f618a00119ba725052c2264cf8ae2ab7a4b9ed56
1c522c9 Mention pathlib performance improvement in news entry. barneygale Jan 22, 2023 https://github.com/python/cpython/pull/101002/commits/1c522c9077ffc4c1e4c188c8c63b6cd3b7c745d5
df17269 Merge branch 'main' into gh-101000-splitroot AlexWaygood Jan 22, 2023 https://github.com/python/cpython/pull/101002/commits/df172692bfca802f83085ecc4ed434deae7c761a
Clear filters https://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Prev https://github.com/python/cpython/pull/101002/commits/11ed3eb55a93fb21bc89ad6a27c7366dab20f0bf
Next https://github.com/python/cpython/pull/101002/commits/8299e969d316a9cd2b391c88cf203f1fa518ddd4
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
https://github.com/barneygale
barneygalehttps://github.com/python/cpython/commits?author=barneygale
Doc/library/os.path.rsthttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38#diff-22dc079c4b2ebb7590f7963d2a7ea70133920c3f465d35b421ec9451c563d783
View file https://github.com/barneygale/cpython/blob/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38/Doc/library/os.path.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/101002/commits/{{ revealButtonHref }}
https://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38#diff-22dc079c4b2ebb7590f7963d2a7ea70133920c3f465d35b421ec9451c563d783
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
Please reload this pagehttps://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
https://github.com/python/cpython/pull/101002/commits/2c9eed88823e840d8b39a34b26ae0e63f0a9fe38#diff-22dc079c4b2ebb7590f7963d2a7ea70133920c3f465d35b421ec9451c563d783
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.