Title: Using a pathlib path with __truediv__ returns a purepath instead of a path · Issue #506 · python/typeshed · GitHub
Open Graph Title: Using a pathlib path with __truediv__ returns a purepath instead of a path · Issue #506 · python/typeshed
X Title: Using a pathlib path with __truediv__ returns a purepath instead of a path · Issue #506 · python/typeshed
Description: This is problematic, let me show with some sample code: $ cat pathproblems.py from pathlib import Path def pathproblems(a: Path) -> bool: return (a / 'hello').exists() if __name__ == '__main__': print(pathproblems(Path('/'))) And the out...
Open Graph Description: This is problematic, let me show with some sample code: $ cat pathproblems.py from pathlib import Path def pathproblems(a: Path) -> bool: return (a / 'hello').exists() if __name__ == '__main__': pr...
X Description: This is problematic, let me show with some sample code: $ cat pathproblems.py from pathlib import Path def pathproblems(a: Path) -> bool: return (a / 'hello').exists() if __name__ == ...
Opengraph URL: https://github.com/python/typeshed/issues/506
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using a pathlib path with __truediv__ returns a purepath instead of a path","articleBody":"This is problematic, let me show with some sample code:\n\n``` Python\n$ cat pathproblems.py \nfrom pathlib import Path\n\ndef pathproblems(a: Path) -> bool:\n return (a / 'hello').exists()\n\nif __name__ == '__main__':\n print(pathproblems(Path('/')))\n```\n\nAnd the output from mypy:\n\n``` bash\n$ mypy pathproblems.py \npathproblems.py: note: In function \"pathproblems\":\npathproblems.py:4: error: \"PurePath\" has no attribute \"exists\"\n```\n\nHere is the signature for PurePath.**truediv**:\n\n``` Python\ndef __truediv__(self, key: Union[str, PurePath]) -> PurePath: ...\n```\n\nThe solution would be for **truediv** to return the type of self isntead of PurePath, is that possible to express using mypy? In my imagination:\n\n``` Python\ndef __truediv__(self, key: Union[str, PurePath]) -> typing.typeof(self):\n```\n\nI've had this issue several times when subclassing where I lose access to my subclass's methods whenever i chain methods from the parent class along the way.\n","author":{"url":"https://github.com/thomascellerier","@type":"Person","name":"thomascellerier"},"datePublished":"2016-08-29T09:14:53Z","url":"https://github.com/python/typeshed/issues/506"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:d23a7d6b-fef6-eb18-1116-ba20a06e911f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E3D6:2046A4:2C012E:3B770B:6B002514 |
| html-safe-nonce | d6b6082a3473e3d1db41b6089b10d5ac28ffa1a85489db4cb080428090addf87 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0Q2OjIwNDZBNDoyQzAxMkU6M0I3NzBCOjZCMDAyNTE0IiwidmlzaXRvcl9pZCI6Ijc1ODE3MTEwNTE3NjMzMTU0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d9aa8b3921d7ebcbd57d71a8c712e7b6ca986ea0fc703246f471aa9bb92f701b |
| hovercard-subject-tag | issue:173730968 |
| 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/typeshed/506/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b814fd65b1ded636dee0d70c965ca83802541aa9dc8bf67be2c9ea4c3776482f/python/typeshed/issues/506 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b814fd65b1ded636dee0d70c965ca83802541aa9dc8bf67be2c9ea4c3776482f/python/typeshed/issues/506 |
| og:image:alt | This is problematic, let me show with some sample code: $ cat pathproblems.py from pathlib import Path def pathproblems(a: Path) -> bool: return (a / 'hello').exists() if __name__ == '__main__': pr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | thomascellerier |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width