Title: Generic Self Type · Issue #2537 · python/mypy · GitHub
Open Graph Title: Generic Self Type · Issue #2537 · python/mypy
X Title: Generic Self Type · Issue #2537 · python/mypy
Description: This is a followup issue to #1212. #2193 enabled method type annotations to refer to the type of self, but (intentionally) didn't address generic classes. In many cases, the self types added there meet the needs of generic classes, but n...
Open Graph Description: This is a followup issue to #1212. #2193 enabled method type annotations to refer to the type of self, but (intentionally) didn't address generic classes. In many cases, the self types added there ...
X Description: This is a followup issue to #1212. #2193 enabled method type annotations to refer to the type of self, but (intentionally) didn't address generic classes. In many cases, the self types added th...
Opengraph URL: https://github.com/python/mypy/issues/2537
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic Self Type","articleBody":"This is a followup issue to #1212. #2193 enabled method type annotations to refer to the type of `self`, but (intentionally) didn't address generic classes. In many cases, the self types added there meet the needs of generic classes, but not always.\r\n\r\nA motivating example is typeshed's AbstractClass:\r\n```\r\nclass AbstractSet(Sized, Iterable[_T_co], Container[_T_co], Generic[_T_co]):\r\n def __and__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ...\r\n def __or__(self, s: AbstractSet[_T]) -> AbstractSet[Union[_T_co, _T]]: ...\r\n```\r\n\r\nWith #2193 we can annotate `__and__`, and it works beautifully:\r\n```\r\n def __and__(self: SelfT, s: AbstractSet[Any]) -> SelfT: ...\r\n```\r\n```\r\ndef f(s, fs):\r\n # type: (MutableSet[str], FrozenSet[str]) -> None\r\n reveal_type(s.__and__) # Revealed type is 'def (typing.AbstractSet[Any]) -> typing.MutableSet[builtins.str]'\r\n reveal_type(fs.__and__) # Revealed type is 'def (typing.AbstractSet[Any]) -> typing.FrozenSet[builtins.str]'\r\n```\r\n\r\nBut, we don't have the tools to give `__or__` a similarly specific type. To do this, we need some way to talk about the \"generic\" part of the self type.","author":{"url":"https://github.com/jboning","@type":"Person","name":"jboning"},"datePublished":"2016-12-08T00:22:23Z","url":"https://github.com/python/mypy/issues/2537"}
| 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:2e314116-a3db-06b6-b019-d64eac666738 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA90:C5FC2:1164A0C:16B8E4D:6B000848 |
| html-safe-nonce | 703571ba8df4656d8f017515afd9e24198a33c770114a4fa37dbce389764fc55 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTkwOkM1RkMyOjExNjRBMEM6MTZCOEU0RDo2QjAwMDg0OCIsInZpc2l0b3JfaWQiOiI4MjIxODI5MzEwNjgwNDAxOTkyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4f22ccc415cf37f5ab7c8b9e73a2f7c42b901a048ebfbccfc284058b8001cd3f |
| hovercard-subject-tag | issue:194214056 |
| 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/2537/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d0e5898716a308927b9fa2a246450206a78e7d6052a1b0ddd30645d0cd45d035/python/mypy/issues/2537 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d0e5898716a308927b9fa2a246450206a78e7d6052a1b0ddd30645d0cd45d035/python/mypy/issues/2537 |
| og:image:alt | This is a followup issue to #1212. #2193 enabled method type annotations to refer to the type of self, but (intentionally) didn't address generic classes. In many cases, the self types added there ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jboning |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width