Title: Disagreement between `PureWindowsPath.relative_to()` and `ntpath.relpath()` with rootless drives · Issue #99029 · python/cpython · GitHub
Open Graph Title: Disagreement between `PureWindowsPath.relative_to()` and `ntpath.relpath()` with rootless drives · Issue #99029 · python/cpython
X Title: Disagreement between `PureWindowsPath.relative_to()` and `ntpath.relpath()` with rootless drives · Issue #99029 · python/cpython
Description: On Windows, the path C: means "the current directory on the C: drive". But pathlib's relative_to() treats it as the immediate parent of C:\. This makes sense lexographically, but it's inconsistent with everything else: C:\Users\Barney>py...
Open Graph Description: On Windows, the path C: means "the current directory on the C: drive". But pathlib's relative_to() treats it as the immediate parent of C:\. This makes sense lexographically, but it's inconsistent ...
X Description: On Windows, the path C: means "the current directory on the C: drive". But pathlib's relative_to() treats it as the immediate parent of C:\. This makes sense lexographically, but it...
Opengraph URL: https://github.com/python/cpython/issues/99029
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Disagreement between `PureWindowsPath.relative_to()` and `ntpath.relpath()` with rootless drives","articleBody":"On Windows, the path `C:` means \"the current directory on the C: drive\".\r\n\r\nBut pathlib's `relative_to()` treats it as the immediate parent of `C:\\`. This makes sense lexographically, but it's inconsistent with everything else:\r\n\r\n```python\r\nC:\\Users\\Barney\u003epython\r\n\u003e\u003e\u003e import ntpath, pathlib\r\n\u003e\u003e\u003e ntpath.relpath('C:/Windows', 'C:/Users/Barney')\r\n'..\\\\..\\\\Windows'\r\n\u003e\u003e\u003e ntpath.relpath('C:/Windows', '.')\r\n'..\\\\..\\\\Windows'\r\n\u003e\u003e\u003e ntpath.relpath('C:/Windows', 'C:')\r\n'..\\\\..\\\\Windows'\r\n\u003e\u003e\u003e pathlib.Path('C:/Windows').relative_to('C:/Users/Barney', walk_up=True)\r\nWindowsPath('../../Windows')\r\n\u003e\u003e\u003e pathlib.Path('C:/Windows').relative_to('.', walk_up=True)\r\nValueError: One path is relative and the other is absolute.\r\n\u003e\u003e\u003e pathlib.Path('C:/Windows').relative_to('C:')\r\nWindowsPath('/Windows') # should be ValueError, as we're mixing absolute + relative paths\r\n```\r\n\r\nThis prevents us from using `relpath()` from pathlib, and renders the two implementations incompatible. Booo! Also prevents us from simplifying `is_relative_to()` down to `other == self or other in self.parents`\r\n\r\nSpecial cases aren't special enough to break the rules. Let's make these compatible!\r\n\r\nPrevious discussion: #84538\r\n\r\n\u003c!-- gh-pr-number: gh-99031 --\u003e\r\n* PR: gh-99031\r\n\u003c!-- /gh-pr-number --\u003e\r\n","author":{"url":"https://github.com/barneygale","@type":"Person","name":"barneygale"},"datePublished":"2022-11-02T23:21:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/99029/cpython/issues/99029"}
| 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:96386e69-1d4e-7a05-0638-94ccc3f722fb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9400:31E362:18F1D8:2145D8:6969768B |
| html-safe-nonce | 2c02112d6eaedda1e6df8632a34d864a16b82c219c04bc37703926089e75d9d4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDAwOjMxRTM2MjoxOEYxRDg6MjE0NUQ4OjY5Njk3NjhCIiwidmlzaXRvcl9pZCI6Ijc0MTM0MzgwMDkzNzg5NjEwMzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 176441e73969b1458e7f1d3b4e8a03f16dd6d743a59917faabe729dfe9585095 |
| hovercard-subject-tag | issue:1433908295 |
| 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/99029/issue_layout |
| twitter:image | https://opengraph.githubassets.com/36802a6af69490e80c5c10177b1f3709b0bb79b22405021602d7ece1c7cd299c/python/cpython/issues/99029 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/36802a6af69490e80c5c10177b1f3709b0bb79b22405021602d7ece1c7cd299c/python/cpython/issues/99029 |
| og:image:alt | On Windows, the path C: means "the current directory on the C: drive". But pathlib's relative_to() treats it as the immediate parent of C:\. This makes sense lexographically, but it's inconsistent ... |
| 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 | c6f193beb8ff08443adc07685d75302ab8aaf0a135f6e251c3ff3112c8deb881 |
| 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 | 212e3e3d3298bf5b313830edfd2399e869f7ea76 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width