Title: Incompatible signature in method with restricted overload for a generic class · Issue #12151 · python/mypy · GitHub
Open Graph Title: Incompatible signature in method with restricted overload for a generic class · Issue #12151 · python/mypy
X Title: Incompatible signature in method with restricted overload for a generic class · Issue #12151 · python/mypy
Description: Bug Report When a method of a generic class has an overload for a particular type of the generic parameter, subclasses that don't have that particular value should be able to override the method without that overload, but currently aren'...
Open Graph Description: Bug Report When a method of a generic class has an overload for a particular type of the generic parameter, subclasses that don't have that particular value should be able to override the method wi...
X Description: Bug Report When a method of a generic class has an overload for a particular type of the generic parameter, subclasses that don't have that particular value should be able to override the metho...
Opengraph URL: https://github.com/python/mypy/issues/12151
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incompatible signature in method with restricted overload for a generic class","articleBody":"**Bug Report**\r\n\r\nWhen a method of a generic class has an overload for a particular type of the generic parameter, subclasses that don't have that particular value should be able to override the method without that overload, but currently aren't.\r\n\r\n**To Reproduce**\r\n\r\nConsider the following code:\r\n```python\r\nT = TypeVar(\"T\")\r\nA_no_T = TypeVar(\r\n \"A_no_T\",\r\n bound=\"A[None]\",\r\n)\r\n\r\n\r\nclass A(\r\n Generic[T],\r\n):\r\n\r\n @overload\r\n def method(\r\n self: A_no_T,\r\n ) -> None:\r\n pass\r\n\r\n @overload\r\n def method(\r\n self,\r\n t: T,\r\n ) -> None:\r\n pass\r\n\r\n def method(\r\n self,\r\n t: Optional[T] = None,\r\n ) -> None:\r\n return\r\n\r\n\r\nclass B(A[int]):\r\n\r\n def method(\r\n self,\r\n t: int,\r\n ) -> None:\r\n pass\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nThe code should typecheck without errors.\r\n\r\n**Actual Behavior**\r\n\r\nThe following error is raised\r\n\r\n```\r\nMypy: Signature of \"method\" incompatible with supertype \"A\" [override]\r\nSuperclass:\r\n@overload\r\ndef method(self) -> None\r\n@overload\r\ndef method(self, t: int) -> None\r\nSubclass:\r\ndef method(self, t: int) -> None\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.931\r\n- Mypy command-line flags: --follow-imports=silent --show-column-numbers --show-error-codes\r\n- Mypy configuration options from `mypy.ini` (and other config files):\r\n strict = True\r\n strict_equality = True\r\n implicit_reexport = True\r\n- Python version used: 3.8.0\r\n- Operating system and version: Linux Ubuntu 18.04.6 LTS","author":{"url":"https://github.com/vnmabus","@type":"Person","name":"vnmabus"},"datePublished":"2022-02-08T18:17:36Z","url":"https://github.com/python/mypy/issues/12151"}
| 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:5777d793-4086-f86a-2441-a7c2c7c9f9a3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E318:21E5F:254ACE:3271A6:6B0023F6 |
| html-safe-nonce | 5af68a324ecf66c309e653c035f312f2b4585285d13bb80c71814946ab053fe3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzE4OjIxRTVGOjI1NEFDRTozMjcxQTY6NkIwMDIzRjYiLCJ2aXNpdG9yX2lkIjoiMjc2NzY4OTM4Mjc0MjcyOTcxOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 29b93f02477e2ecb6c00df074e253ec453192b64b0ded765e3f0ba165170fde3 |
| hovercard-subject-tag | issue:1127604136 |
| 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/12151/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2f9e996bb5cffd7f989b6c4f1466829be792c8068e3a8f50e801fd0cc348c44a/python/mypy/issues/12151 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2f9e996bb5cffd7f989b6c4f1466829be792c8068e3a8f50e801fd0cc348c44a/python/mypy/issues/12151 |
| og:image:alt | Bug Report When a method of a generic class has an overload for a particular type of the generic parameter, subclasses that don't have that particular value should be able to override the method wi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vnmabus |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width