Title: All standard library functions accepting `str` paths must accept `PathLike` as well · Issue #102425 · python/cpython · GitHub
Open Graph Title: All standard library functions accepting `str` paths must accept `PathLike` as well · Issue #102425 · python/cpython
X Title: All standard library functions accepting `str` paths must accept `PathLike` as well · Issue #102425 · python/cpython
Description: Inspired by gh-3484 that tried to fix this for wave.open() only but failed. We need a centralized and universal approach instead so everything accepting str paths could automatically accept PathLike for free. For this, we can amend stdli...
Open Graph Description: Inspired by gh-3484 that tried to fix this for wave.open() only but failed. We need a centralized and universal approach instead so everything accepting str paths could automatically accept PathLik...
X Description: Inspired by gh-3484 that tried to fix this for wave.open() only but failed. We need a centralized and universal approach instead so everything accepting str paths could automatically accept PathLik...
Opengraph URL: https://github.com/python/cpython/issues/102425
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"All standard library functions accepting `str` paths must accept `PathLike` as well","articleBody":"*Inspired by gh-3484 that tried to fix this for `wave.open()` only but failed.*\r\n\r\nWe need a centralized and universal approach instead so everything accepting `str` paths could automatically accept `PathLike` for free.\r\n\r\nFor this, we can amend stdlib functions to wrap their path arguments into `pathlib.PurePath` introduced in Python 3.4. Unlike `os.fspath`, it throws a nicely formatted exception for us:\r\n\r\n- `os.fspath` from the mentioned gh-3484: https://github.com/python/cpython/blob/4a82d651b5472641f966959e046b89f0ade3a8a7/Lib/aifc.py#L912-L918\r\n- `PurePath`:\r\n\r\n ```python\r\n \u003e\u003e\u003e import pathlib\r\n \u003e\u003e\u003e pathlib.PurePath(16)\r\n Traceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\n File \"D:\\Oleg\\cpython\\Lib\\pathlib.py\", line 267, in __new__\r\n return cls._from_parts(args)\r\n ^^^^^^^^^^^^^^^^^^^^^\r\n File \"D:\\Oleg\\cpython\\Lib\\pathlib.py\", line 316, in _from_parts\r\n drv, root, parts = self._parse_args(args)\r\n ^^^^^^^^^^^^^^^^^^^^^^\r\n File \"D:\\Oleg\\cpython\\Lib\\pathlib.py\", line 300, in _parse_args\r\n a = os.fspath(a)\r\n ^^^^^^^^^^^^\r\n TypeError: expected str, bytes or os.PathLike object, not int\r\n ```","author":{"url":"https://github.com/arhadthedev","@type":"Person","name":"arhadthedev"},"datePublished":"2023-03-04T18:27:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/102425/cpython/issues/102425"}
| 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:db838e8d-8104-d71b-900d-974cff431cf3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD00:372616:3C3F668:55893E6:6A56BA38 |
| html-safe-nonce | fb01f3dcb0088c02974d27133c2657408d4d146c7c3aa81cbc2e61beaa329097 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDAwOjM3MjYxNjozQzNGNjY4OjU1ODkzRTY6NkE1NkJBMzgiLCJ2aXNpdG9yX2lkIjoiMTk1NDEyMTM3NDU1NDgzMTQxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 580a9f762850e2d33bea118a26e96f6dac53c24016423e1b8bbe6c851bc0f156 |
| hovercard-subject-tag | issue:1609889646 |
| 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/102425/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7b3d1bead2cc4681be53250d047b229a7ddf9222b7af765b9e094961c19994b9/python/cpython/issues/102425 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7b3d1bead2cc4681be53250d047b229a7ddf9222b7af765b9e094961c19994b9/python/cpython/issues/102425 |
| og:image:alt | Inspired by gh-3484 that tried to fix this for wave.open() only but failed. We need a centralized and universal approach instead so everything accepting str paths could automatically accept PathLik... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | arhadthedev |
| hostname | github.com |
| expected-hostname | github.com |
| None | df99b7164e1d961b639cf5d3cbd6b5ba673edc67bd7e47cdc4746b96099e11ae |
| 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 | c29ba03b1896083dbe1084f6cd1c5367d8a0d67c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width