Title: Detect unsupported use of self types in generic classes · Issue #8020 · python/mypy · GitHub
Open Graph Title: Detect unsupported use of self types in generic classes · Issue #8020 · python/mypy
X Title: Detect unsupported use of self types in generic classes · Issue #8020 · python/mypy
Description: The last line generates a strange error message: from typing import TypeVar, Generic, Type M = TypeVar("M") T = TypeVar("T") class Descriptor(Generic[M]): pass class BaseWrapper(Generic[M]): @classmethod def create_wrapper(cls, metric_de...
Open Graph Description: The last line generates a strange error message: from typing import TypeVar, Generic, Type M = TypeVar("M") T = TypeVar("T") class Descriptor(Generic[M]): pass class BaseWrapper(Generic[M]): @class...
X Description: The last line generates a strange error message: from typing import TypeVar, Generic, Type M = TypeVar("M") T = TypeVar("T") class Descriptor(Generic[M]): pass class BaseWrapper...
Opengraph URL: https://github.com/python/mypy/issues/8020
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Detect unsupported use of self types in generic classes","articleBody":"The last line generates a strange error message:\r\n\r\n```py\r\nfrom typing import TypeVar, Generic, Type\r\n\r\nM = TypeVar(\"M\")\r\nT = TypeVar(\"T\")\r\n\r\nclass Descriptor(Generic[M]):\r\n pass\r\n\r\nclass BaseWrapper(Generic[M]):\r\n @classmethod\r\n def create_wrapper(cls, metric_descriptor):\r\n # type: (Type[T], Descriptor[M]) -> T\r\n raise NotImplementedError\r\n \r\nclass WrapperInstance(BaseWrapper[M]):\r\n @classmethod\r\n def create_wrapper(cls, descriptor):\r\n # type: (Descriptor[M]) -> WrapperInstance[M]\r\n return WrapperInstance()\r\n \r\ndef build_wrapper(descriptor):\r\n # type: (Descriptor[M]) -> BaseWrapper[M]\r\n wrapper = WrapperInstance # type: Type[BaseWrapper[M]]\r\n # Argument 1 to \"create_wrapper\" of \"BaseWrapper\" has incompatible type \"Descriptor[M]\"; \r\n # expected \"Descriptor[BaseWrapper[M]]\"\r\n return wrapper.create_wrapper(descriptor)\r\n```\r\n\r\nThe root cause seems to be the signature of `BaseWrapper.create_wrapper`; it shouldn't use two type variables `M` and `T`. It would be better to generate an error about the signature instead of the call site. However, there may be something deeper going on.","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2019-11-27T10:37:02Z","url":"https://github.com/python/mypy/issues/8020"}
| 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:121bdc11-a80b-9f32-621d-4e5d7582f542 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8534:381DB6:12FD905:18CE6D1:6B00056A |
| html-safe-nonce | 31faf21761633320d0c1748495eb06bd472a7a368566f5e3ecee11055e6959c5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTM0OjM4MURCNjoxMkZEOTA1OjE4Q0U2RDE6NkIwMDA1NkEiLCJ2aXNpdG9yX2lkIjoiMzUzNDIxMDQ4NjY2Mjg1ODA5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0623ff1cc1ecf8701ca23526cfec8d90479ada4415151ebbdca39662556bcbc6 |
| hovercard-subject-tag | issue:529260025 |
| 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/8020/issue_layout |
| twitter:image | https://opengraph.githubassets.com/97bd173866da6181509ff08433d84d61b852213e086990f5b334d451c0f9e2cb/python/mypy/issues/8020 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/97bd173866da6181509ff08433d84d61b852213e086990f5b334d451c0f9e2cb/python/mypy/issues/8020 |
| og:image:alt | The last line generates a strange error message: from typing import TypeVar, Generic, Type M = TypeVar("M") T = TypeVar("T") class Descriptor(Generic[M]): pass class BaseWrapper(Generic[M]): @class... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JukkaL |
| 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