Title: support pep 673 Self type · Issue #11871 · python/mypy · GitHub
Open Graph Title: support pep 673 Self type · Issue #11871 · python/mypy
X Title: support pep 673 Self type · Issue #11871 · python/mypy
Description: Feature Support the pep-673 Self type pep is at: https://www.python.org/dev/peps/pep-0673/ a rough idea of it is that this code: from typing import Self class Widget: def add_thing(self, value: str) -> Self: self.value = value return sel...
Open Graph Description: Feature Support the pep-673 Self type pep is at: https://www.python.org/dev/peps/pep-0673/ a rough idea of it is that this code: from typing import Self class Widget: def add_thing(self, value: str...
X Description: Feature Support the pep-673 Self type pep is at: https://www.python.org/dev/peps/pep-0673/ a rough idea of it is that this code: from typing import Self class Widget: def add_thing(self, value: str...
Opengraph URL: https://github.com/python/mypy/issues/11871
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"support pep 673 Self type","articleBody":"**Feature**\r\n\r\nSupport the pep-673 Self type\r\n\r\npep is at: https://www.python.org/dev/peps/pep-0673/\r\n\r\na rough idea of it is that this code:\r\n\r\n```py\r\nfrom typing import Self\r\n\r\nclass Widget:\r\n def add_thing(self, value: str) -> Self:\r\n self.value = value\r\n return self\r\n\r\n```\r\n\r\nis quasi-equivalent to:\r\n\r\n```py\r\n\r\nfrom typing import TypeVar\r\n\r\nTWidget = TypeVar(\"TWidget\", bound=\"Widget\")\r\n\r\nclass Widget:\r\n def add_thing(self: TWidget, value: str) -> TWidget:\r\n self.value = value\r\n return self\r\n\r\n```\r\n\r\n**Pitch**\r\n\r\nthe appeal of the pep is that for the very common pattern of method-chained object construction, methods can easily indicate they return an object of the same type upon which the method is being invoked. For example if I made `class SubWidget(Widget)`, the `SubWidget.add_thing()` method reports `SubWidget` as the return type automatically. The pattern using TypeVar seems to be more or less equivlant, but is more verbose requiring the declaration of TypeVar objects per class hierarchy as well as that it has to be explicitly present on the \"self\" parameter in methods.\r\n\r\nWe are looking for this feature to make our job of integrating typing into SQLAlchemy an easier job. it seems to be a fairly straightforward translation between two idioms.\r\n\r\n\r\ncc @caselit\r\n\r\n","author":{"url":"https://github.com/zzzeek","@type":"Person","name":"zzzeek"},"datePublished":"2021-12-29T21:28:05Z","url":"https://github.com/python/mypy/issues/11871"}
| 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:d7ad7066-2b3a-117f-4f12-126d4a6bbe40 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C528:22BD05:236D688:30118E7:6B002D4D |
| html-safe-nonce | 24861afa5c4c5356d2813acab2f7c37d7dc08fdf00884bfbf12b989a80393195 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTI4OjIyQkQwNToyMzZENjg4OjMwMTE4RTc6NkIwMDJENEQiLCJ2aXNpdG9yX2lkIjoiNzYyODE0MDc4NzQyMjczNTY5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9ee63669cd0340cb174823dffd0f734ef412627f6785b4dbd9d3684913be79c7 |
| hovercard-subject-tag | issue:1090757115 |
| 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/11871/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6179dd8e11b87884bbddd757347082eed8807f679b5be3edcdfc0dd13d6c652f/python/mypy/issues/11871 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6179dd8e11b87884bbddd757347082eed8807f679b5be3edcdfc0dd13d6c652f/python/mypy/issues/11871 |
| og:image:alt | Feature Support the pep-673 Self type pep is at: https://www.python.org/dev/peps/pep-0673/ a rough idea of it is that this code: from typing import Self class Widget: def add_thing(self, value: str... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zzzeek |
| 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