Title: User subclasses of `pathlib.PurePath` are `os.PathLike` · Issue #106037 · python/cpython · GitHub
Open Graph Title: User subclasses of `pathlib.PurePath` are `os.PathLike` · Issue #106037 · python/cpython
X Title: User subclasses of `pathlib.PurePath` are `os.PathLike` · Issue #106037 · python/cpython
Description: In Python 3.12 we've made pathlib.PurePath subclassable - see #31691. A significant wrinkle is that subclasses inherit an __fspath__() method, which can lead to unexpected behaviour when these "pure" paths are passed to filesystem APIs: ...
Open Graph Description: In Python 3.12 we've made pathlib.PurePath subclassable - see #31691. A significant wrinkle is that subclasses inherit an __fspath__() method, which can lead to unexpected behaviour when these "pur...
X Description: In Python 3.12 we've made pathlib.PurePath subclassable - see #31691. A significant wrinkle is that subclasses inherit an __fspath__() method, which can lead to unexpected behaviour when these ...
Opengraph URL: https://github.com/python/cpython/issues/106037
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"User subclasses of `pathlib.PurePath` are `os.PathLike`","articleBody":"In Python 3.12 we've made `pathlib.PurePath` subclassable - see #31691.\r\n\r\nA significant wrinkle is that subclasses inherit an `__fspath__()` method, which can lead to unexpected behaviour when these \"pure\" paths are passed to filesystem APIs:\r\n\r\n```python\r\nimport pathlib\r\n\r\nclass TarPath(pathlib.PurePath):\r\n ...\r\n\r\nreadme = TarPath('README.md', tarfile=...)\r\nwith open(readme) as f:\r\n ...\r\n```\r\n\r\nThe `with open(readme) as f:` line should throw a `TypeError`, but instead it attempts to open a file called README.md in the current working directory (!). This sort of thing makes subclasses that implement purely virtual filesystems difficult to use safely.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-106043\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/barneygale","@type":"Person","name":"barneygale"},"datePublished":"2023-06-23T17:03:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/106037/cpython/issues/106037"}
| 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:18f1592e-0251-59c7-021a-0f41bc134069 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E97E:3E9801:550BD1:7223C8:6969CA4A |
| html-safe-nonce | 86e6128c35f03cef00d7087eb83ecb956e2f6bc822072d9126323872cc6636d2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOTdFOjNFOTgwMTo1NTBCRDE6NzIyM0M4OjY5NjlDQTRBIiwidmlzaXRvcl9pZCI6IjkwNTIxNjMyMDkwMDE4MTQ2MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 17238d2ceb4561df7c1a230101f4434ae30e33ce7780a9e9765b676ab9361a56 |
| hovercard-subject-tag | issue:1771779163 |
| 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/106037/issue_layout |
| twitter:image | https://opengraph.githubassets.com/89d7e5b9dff5d58c5786854f51fb5e304f37fb67eed19c562b362a4300c35320/python/cpython/issues/106037 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/89d7e5b9dff5d58c5786854f51fb5e304f37fb67eed19c562b362a4300c35320/python/cpython/issues/106037 |
| og:image:alt | In Python 3.12 we've made pathlib.PurePath subclassable - see #31691. A significant wrinkle is that subclasses inherit an __fspath__() method, which can lead to unexpected behaviour when these "pur... |
| 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 | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| 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 | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width