Title: Generic Self classmethod fails for generic types · Issue #3631 · python/mypy · GitHub
Open Graph Title: Generic Self classmethod fails for generic types · Issue #3631 · python/mypy
X Title: Generic Self classmethod fails for generic types · Issue #3631 · python/mypy
Description: Repro: from typing import Generic, TypeVar, Type _T = TypeVar('_T') SelfType = TypeVar('SelfType', bound='Friend') class Friend(Generic[_T]): @classmethod def make(cls: Type[SelfType]) -> SelfType: # E: Unsupported type Type["SelfType"] ...
Open Graph Description: Repro: from typing import Generic, TypeVar, Type _T = TypeVar('_T') SelfType = TypeVar('SelfType', bound='Friend') class Friend(Generic[_T]): @classmethod def make(cls: Type[SelfType]) -> SelfType:...
X Description: Repro: from typing import Generic, TypeVar, Type _T = TypeVar('_T') SelfType = TypeVar('SelfType', bound='Friend') class Friend(Generic[_T]): @classmethod def make(cls: Type...
Opengraph URL: https://github.com/python/mypy/issues/3631
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic Self classmethod fails for generic types","articleBody":"Repro:\r\n\r\n```python\r\nfrom typing import Generic, TypeVar, Type\r\n\r\n_T = TypeVar('_T')\r\nSelfType = TypeVar('SelfType', bound='Friend')\r\n\r\nclass Friend(Generic[_T]):\r\n @classmethod\r\n def make(cls: Type[SelfType]) -> SelfType: # E: Unsupported type Type[\"SelfType\"]\r\n return cls()\r\n```\r\n\r\nI suspect the issue is that the type _should_ be:\r\n\r\n```python\r\ndef make(cls: Type[SelfType[T]]) -> SelfType[T]:\r\n return cls()\r\n```\r\n\r\nBut there is no way to express that that I can tell.\r\n\r\nUsing an instance method behaves as expected:\r\n```\r\nfrom typing import Generic, TypeVar, Type\r\n\r\n_T = TypeVar('_T')\r\nSelfType = TypeVar('SelfType', bound='Friend')\r\n\r\nclass Friend(Generic[_T]):\r\n other = None # type: Friend\r\n\r\n def make(self: SelfType) -> SelfType:\r\n return self\r\n```\r\n","author":{"url":"https://github.com/rowillia","@type":"Person","name":"rowillia"},"datePublished":"2017-06-29T06:20:17Z","url":"https://github.com/python/mypy/issues/3631"}
| 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:67e3984e-aa6f-0f72-d0e1-75d426e3d48b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BF70:1B6970:2563B8:331D06:6B006884 |
| html-safe-nonce | 75288f89050426f8525a2f1a141da5c671fba4084aebff998a292b30db2411b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRjcwOjFCNjk3MDoyNTYzQjg6MzMxRDA2OjZCMDA2ODg0IiwidmlzaXRvcl9pZCI6IjkwMzQ0OTA2NDI2NzExMDIwODQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 910f19faf671920fe329d14a7f83523082f171f28a5050abd69e906e94667efa |
| hovercard-subject-tag | issue:239376548 |
| 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/3631/issue_layout |
| twitter:image | https://opengraph.githubassets.com/72aad04eb8332c599e4ec6af7e3ff584cc5f01c04b8f9dd09f3019d3b55170a0/python/mypy/issues/3631 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/72aad04eb8332c599e4ec6af7e3ff584cc5f01c04b8f9dd09f3019d3b55170a0/python/mypy/issues/3631 |
| og:image:alt | Repro: from typing import Generic, TypeVar, Type _T = TypeVar('_T') SelfType = TypeVar('SelfType', bound='Friend') class Friend(Generic[_T]): @classmethod def make(cls: Type[SelfType]) -> SelfType:... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rowillia |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| 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 | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width