Title: supertype incompatibility with subclass classmethod · Issue #8495 · python/mypy · GitHub
Open Graph Title: supertype incompatibility with subclass classmethod · Issue #8495 · python/mypy
X Title: supertype incompatibility with subclass classmethod · Issue #8495 · python/mypy
Description: I am currently trying to apply type hints to a base class and its subclasses which override a classmethod: from abc import ABCMeta, abstractmethod from typing import TypeVar, Type class MyBase(metaclass=ABCMeta): @classmethod @abstractme...
Open Graph Description: I am currently trying to apply type hints to a base class and its subclasses which override a classmethod: from abc import ABCMeta, abstractmethod from typing import TypeVar, Type class MyBase(meta...
X Description: I am currently trying to apply type hints to a base class and its subclasses which override a classmethod: from abc import ABCMeta, abstractmethod from typing import TypeVar, Type class MyBase(meta...
Opengraph URL: https://github.com/python/mypy/issues/8495
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"supertype incompatibility with subclass classmethod","articleBody":"I am currently trying to apply type hints to a base class and its subclasses which override a classmethod:\r\n\r\n```python\r\nfrom abc import ABCMeta, abstractmethod\r\nfrom typing import TypeVar, Type\r\n\r\nclass MyBase(metaclass=ABCMeta):\r\n @classmethod\r\n @abstractmethod\r\n def foo(cls) -> MyBase:\r\n pass\r\n\r\n\r\nclass MyChild(MyBase):\r\n @classmethod\r\n def foo(cls) -> MyChild:\r\n return MyChild()\r\n\r\n_MyT = TypeVar(\"_MyT\", bound=MyBase)\r\n\r\ndef bar(clazz: Type[_MyT]) -> _MyT:\r\n return clazz.foo()\r\n```\r\n\r\nError:\r\n```\r\nexample.py:19: error: Incompatible return value type (got \"MyBase\", expected \"_MyT\")\r\n```\r\n\r\nThis seems to be incorrect, as returing `MyBase` is in bounds of `_MyT`.\r\n\r\nI have found #2511 and its fix #7474 which should be merged in `0.761` but I still get this error.\r\n\r\nPython: 3.8.1\r\nMyPy: 0.761 (no custom flags)","author":{"url":"https://github.com/bephinix","@type":"Person","name":"bephinix"},"datePublished":"2020-03-05T16:02:31Z","url":"https://github.com/python/mypy/issues/8495"}
| 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:dd626a2b-cfbb-9ad2-9ac9-cc87c26bd559 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AAE2:3A7693:236749A:300A4C6:6B0029D6 |
| html-safe-nonce | b2dea5328041e965fc0d4cf44bbabb9d897ebe33b045dd037a8f8c812060a90b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUUyOjNBNzY5MzoyMzY3NDlBOjMwMEE0QzY6NkIwMDI5RDYiLCJ2aXNpdG9yX2lkIjoiNTIwMTE2NTg4MzU1MjA0OTYyMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 888fd98f34f72a08c1496e12aaf65cb23485b46d55197106bb83a4d11124fd43 |
| hovercard-subject-tag | issue:576360723 |
| 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/8495/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e6b5ae2c099839ae97662c0866079764774d8e28b720921b39fe8a4438276d26/python/mypy/issues/8495 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e6b5ae2c099839ae97662c0866079764774d8e28b720921b39fe8a4438276d26/python/mypy/issues/8495 |
| og:image:alt | I am currently trying to apply type hints to a base class and its subclasses which override a classmethod: from abc import ABCMeta, abstractmethod from typing import TypeVar, Type class MyBase(meta... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bephinix |
| 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