Title: Add os.path.splitroot() function · Issue #101000 · python/cpython · GitHub
Open Graph Title: Add os.path.splitroot() function · Issue #101000 · python/cpython
X Title: Add os.path.splitroot() function · Issue #101000 · python/cpython
Description: Feature or enhancement Add a function that splits a path into a (drive, root, tail) triad: The drive part has the same meaning as in splitdrive() The root part is one of: the empty string, a forward slash, a backward slash (Windows only)...
Open Graph Description: Feature or enhancement Add a function that splits a path into a (drive, root, tail) triad: The drive part has the same meaning as in splitdrive() The root part is one of: the empty string, a forwar...
X Description: Feature or enhancement Add a function that splits a path into a (drive, root, tail) triad: The drive part has the same meaning as in splitdrive() The root part is one of: the empty string, a forwar...
Opengraph URL: https://github.com/python/cpython/issues/101000
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add os.path.splitroot() function","articleBody":"# Feature or enhancement\r\n\r\nAdd a function that splits a path into a `(drive, root, tail)` triad:\r\n\r\n1. The _drive_ part has the same meaning as in `splitdrive()`\r\n2. The _root_ part is one of: the empty string, a forward slash, a backward slash (Windows only), or two forward slashes (POSIX only)\r\n3. The _tail_ part is everything following the root.\r\n\r\nSimilarly to `splitdrive()`, a `splitroot()` function would ensure that `drive + root + tail` is the same as the input path.\r\n\r\n# Pitch\r\nThe 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'\r\n\r\nThis 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 a `relative_to()` operation is possible.\r\n\r\nPathlib has [its own implementation of `splitroot()`](https://github.com/python/cpython/blob/08e5594cf3d42391a48e0311f6b9393ec2e00e1e/Lib/pathlib.py#L274-L285), but its performance is hamstrung by its need for OS-agnosticism. By moving the implementation into `ntpath` and `posixpath` we can take advantage of OS-specific rules to improve pathlib performance. \r\n\r\n# Previous discussion\r\n\r\n- https://discuss.python.org/t/add-os-path-splitroot/22243\r\n- https://github.com/python/cpython/pull/31691/files#r944987609\r\n- https://github.com/python/cpython/pull/100351/files/5b67a7489e5518975d0c11033cd35bf60fad0ddf#r1065219273\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-101002\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/barneygale","@type":"Person","name":"barneygale"},"datePublished":"2023-01-12T19:38:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/101000/cpython/issues/101000"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:06384a8a-f04d-09e9-f450-fa5012e376e4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 82B6:274FD0:AD580E:EC2E81:69697D7E |
| html-safe-nonce | 278ca4e21e8eb6e8fc2a4bbbf03a9505b2e02a91fb596511533dd2b2344f7f38 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkI2OjI3NEZEMDpBRDU4MEU6RUMyRTgxOjY5Njk3RDdFIiwidmlzaXRvcl9pZCI6IjkxOTc4MTA1MTA2OTYzODE4MjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5d66766a179d894fe90e2fcb64ded8ba7e33cf46370d4b8b0e4b2d9a3dcde7cd |
| hovercard-subject-tag | issue:1531255710 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/101000/issue_layout |
| twitter:image | https://opengraph.githubassets.com/26fa99da52394fc078731adb2a5e688fa42fdb8b42124e37347439365fdcbb98/python/cpython/issues/101000 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/26fa99da52394fc078731adb2a5e688fa42fdb8b42124e37347439365fdcbb98/python/cpython/issues/101000 |
| og:image:alt | Feature or enhancement Add a function that splits a path into a (drive, root, tail) triad: The drive part has the same meaning as in splitdrive() The root part is one of: the empty string, a forwar... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | barneygale |
| hostname | github.com |
| expected-hostname | github.com |
| None | f33e4b94c8824ab2b434d82a94139432fb5ebee9df4b75304140ad22508c4a77 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 48f380098b30acbb700b04f1724481ca10d574fc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width