Title: Self-type doesn't seem to work for properties · Issue #2402 · python/mypy · GitHub
Open Graph Title: Self-type doesn't seem to work for properties · Issue #2402 · python/mypy
X Title: Self-type doesn't seem to work for properties · Issue #2402 · python/mypy
Description: I found this when trying to use self-type for pathlib (see PR python/typeshed#658). There are a few properties that have type PurePath and are repeated in the Path subclass. The stub uses plain attributes for these, but the implementatio...
Open Graph Description: I found this when trying to use self-type for pathlib (see PR python/typeshed#658). There are a few properties that have type PurePath and are repeated in the Path subclass. The stub uses plain att...
X Description: I found this when trying to use self-type for pathlib (see PR python/typeshed#658). There are a few properties that have type PurePath and are repeated in the Path subclass. The stub uses plain att...
Opengraph URL: https://github.com/python/mypy/issues/2402
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Self-type doesn't seem to work for properties","articleBody":"I found this when trying to use self-type for pathlib (see PR python/typeshed#658). There are a few properties that have type PurePath and are repeated in the Path subclass. The stub uses plain attributes for these, but the implementation has properties, so I want to replace them with properties. However this doesn't seem to work. In particular I'm trying to add this to class PurePath:\r\n```\r\n @property\r\n def parents(self: _P) -> Sequence[_P]: ...\r\n @property\r\n def parent(self: _P) -> _P: ...\r\n```\r\nNow I have an example class:\r\n```\r\nclass MyPath(pathlib.PosixPath):\r\n def parity(self):\r\n return len(str(self)) % 2\r\n\r\nroot = MyPath('/')\r\nreveal_type(root.parent)\r\n\r\n```\r\nThis reveals MyPath as the type but *also* gives an error:\r\n```\r\n__tmp__.py:14: error: Revealed type is '__tmp__.MyPath*'\r\n__tmp__.py:14: error: Invalid method type\r\n```\r\nIf I remove the self-type, e.g.\r\n```\r\n @property\r\n def parents(self) -> Sequence[PurePath]: ...\r\n @property\r\n def parent(self) -> PurePath: ...\r\n```\r\nthe error goes away but the revealed type reverts back to (of course) PurePath.\r\n\r\n@elazarg thoughts?","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2016-11-04T22:32:29Z","url":"https://github.com/python/mypy/issues/2402"}
| 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:dfcc6295-b2d2-4ddd-13c5-ba73dd00548f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8954:3E1398:A27471:D98CBC:6B00467D |
| html-safe-nonce | 268fbdfa4e5a731ae8874afa8411ecc21d8b20e2edfdfc495c48793bd57699a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTU0OjNFMTM5ODpBMjc0NzE6RDk4Q0JDOjZCMDA0NjdEIiwidmlzaXRvcl9pZCI6IjQ4Mjg3MzI2MjYzMTc2MjQ5NTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 19981aaf5ed1b87196b8eb92e877b6ea9a115454dd4284c37751bc9c9684eedd |
| hovercard-subject-tag | issue:187452441 |
| 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/mypy/2402/issue_layout |
| twitter:image | https://opengraph.githubassets.com/68f6bfec1457df357ce691f0083a0ba90f73ffa4ffaf23def76626f99448d876/python/mypy/issues/2402 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/68f6bfec1457df357ce691f0083a0ba90f73ffa4ffaf23def76626f99448d876/python/mypy/issues/2402 |
| og:image:alt | I found this when trying to use self-type for pathlib (see PR python/typeshed#658). There are a few properties that have type PurePath and are repeated in the Path subclass. The stub uses plain att... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gvanrossum |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width