Title: A way to spell "SelfType", the type of self · Issue #271 · python/typing · GitHub
Open Graph Title: A way to spell "SelfType", the type of self · Issue #271 · python/typing
X Title: A way to spell "SelfType", the type of self · Issue #271 · python/typing
Description: See python/mypy#1212. The proposal does not require changes to typing.py but it could benefit from words in PEP 484 requiring that this works. The idea is simple: in an instance method, you can add a type annotation for self which is a t...
Open Graph Description: See python/mypy#1212. The proposal does not require changes to typing.py but it could benefit from words in PEP 484 requiring that this works. The idea is simple: in an instance method, you can add...
X Description: See python/mypy#1212. The proposal does not require changes to typing.py but it could benefit from words in PEP 484 requiring that this works. The idea is simple: in an instance method, you can add...
Opengraph URL: https://github.com/python/typing/issues/271
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"A way to spell \"SelfType\", the type of self","articleBody":"See https://github.com/python/mypy/issues/1212. The proposal does not require changes to typing.py but it could benefit from words in PEP 484 requiring that this works.\n\nThe idea is simple: in an instance method, you can add a type annotation for `self` which is a type variable, and make the return type use that same type variable, e.g.\n\n``` python\nT = TypeVar('T', bound='Copyable')\nclass Copyable:\n def copy(self: T) -> T:\n # return a copy of self\nclass C(Copyable): ...\nc = C()\nc2 = c.copy() # type here should be C\n```\n\nIt should also work for class methods, using `Type[]`, e.g.\n\n``` python\nT = TypeVar('T', bound='C')\nclass C:\n def factory(cls: Type[T]) -> T:\n # make a new instance of cls\nclass D(C): ...\nd = D.factory() # type here should be D\n```\n\nNote that the Python 2 annotation syntax already supports this, e.g.\n\n``` python\nT = TypeVar('T', bound='Copyable')\nclass Copyable:\n def copy(self):\n # type: (T) -> T\n # etc.\n```\n\n(IOW if you have a method with `self` and three arguments, you can give it either 3 or 4 arguments in the `# type:` comment, and if 4, the first will be used for `self`. Ditto for class methods.)\n","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2016-08-28T17:02:08Z","url":"https://github.com/python/typing/issues/271"}
| 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:8e31dbd7-1296-57e0-ed1f-75ffc23d041f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC4C:2573D7:215FA7D:2D77540:6B002466 |
| html-safe-nonce | 244e51050a8d5c7dd7ffefa470b818ecb72c86ab41c3191a54bf5267d510e5ba |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzRDOjI1NzNENzoyMTVGQTdEOjJENzc1NDA6NkIwMDI0NjYiLCJ2aXNpdG9yX2lkIjoiMzY2NDkzODUyNzk2NTA2MjI0NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cdd53a3743d4e9cc50f35c4e072d74b13d33d52450d12041fc66fcf912651487 |
| hovercard-subject-tag | issue:173656305 |
| 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/typing/271/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c7f2340a53a2891602375266e492c709590635a55bd24951e3978e4b9fd1cc25/python/typing/issues/271 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c7f2340a53a2891602375266e492c709590635a55bd24951e3978e4b9fd1cc25/python/typing/issues/271 |
| og:image:alt | See python/mypy#1212. The proposal does not require changes to typing.py but it could benefit from words in PEP 484 requiring that this works. The idea is simple: in an instance method, you can add... |
| 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 | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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