Title: Type variable return value from class methods · Issue #3438 · python/mypy · GitHub
Open Graph Title: Type variable return value from class methods · Issue #3438 · python/mypy
X Title: Type variable return value from class methods · Issue #3438 · python/mypy
Description: mypy gets confused about the type of a type variable return value from a class method: from typing import TypeVar from typing import Generic P=TypeVar('P') class G(Generic[P]): @classmethod def c(cls) -> 'P': assert False def s(self) -> ...
Open Graph Description: mypy gets confused about the type of a type variable return value from a class method: from typing import TypeVar from typing import Generic P=TypeVar('P') class G(Generic[P]): @classmethod def c(c...
X Description: mypy gets confused about the type of a type variable return value from a class method: from typing import TypeVar from typing import Generic P=TypeVar('P') class G(Generic[P]): @classmethod...
Opengraph URL: https://github.com/python/mypy/issues/3438
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type variable return value from class methods","articleBody":"`mypy` gets confused about the type of a type variable return value from a class method:\r\n\r\n```python\r\n\r\nfrom typing import TypeVar\r\nfrom typing import Generic\r\n\r\nP=TypeVar('P')\r\n\r\nclass G(Generic[P]):\r\n\r\n @classmethod\r\n def c(cls) -> 'P':\r\n assert False\r\n\r\n def s(self) -> 'P':\r\n assert False\r\n\r\nclass C:\r\n pass\r\n\r\nclass GC(G[C]):\r\n pass\r\n\r\nc = C()\r\nc = GC().s() # OK\r\nc = GC.c() # error: Incompatible types in assignment (expression has type \"P\", variable has type \"C\")\r\n```\r\n\r\nThis is causing a huge PITA in my code...\r\n\r\nActually, in my code I would *really* want to make `c` a `@classproperty`, that is, be able to write `GC.c` instead of `GC.c()`. I can implement a `@classproperty` decorator by myself, of course, but that would mean giving up on any hope whatsoever of `mypy` being able to type-check my code. Of course, in an ideal world, one would just be able to say both `@property` and `@classmethod`, but they don't compose... Sigh.\r\n\r\nI expected the simple `@classmethod` to work, though. I _assume_ this is a bug? Is there a workaround?\r\n\r\nBTW - I am using `mypy` 0.501 and Python 3.6.0, if that matters...","author":{"url":"https://github.com/orenbenkiki","@type":"Person","name":"orenbenkiki"},"datePublished":"2017-05-24T11:32:51Z","url":"https://github.com/python/mypy/issues/3438"}
| 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:67a07da1-cffb-7d02-2e66-c09490aa2bbd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 86CA:396A8E:1073CBF:159BACC:6B00084D |
| html-safe-nonce | aa5b74d58776d85be9554e904407b3249e02bf570a5bbedcd12e95541484e63a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NkNBOjM5NkE4RToxMDczQ0JGOjE1OUJBQ0M6NkIwMDA4NEQiLCJ2aXNpdG9yX2lkIjoiNTg5MDA3NzA5NzU2NDc4MjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | eaf526889e1a668329b5b26760f008b1d7841cf19c14a773590e11a7519adbff |
| hovercard-subject-tag | issue:231008930 |
| 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/3438/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9581c8a113bd631e3b846ace4ee3c345fad0ed32b76a2fa46274969ca909b2df/python/mypy/issues/3438 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9581c8a113bd631e3b846ace4ee3c345fad0ed32b76a2fa46274969ca909b2df/python/mypy/issues/3438 |
| og:image:alt | mypy gets confused about the type of a type variable return value from a class method: from typing import TypeVar from typing import Generic P=TypeVar('P') class G(Generic[P]): @classmethod def c(c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | orenbenkiki |
| 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