Title: Moving an overloaded generic function into a class can sometimes introduce "incompatible return type" errors · Issue #5510 · python/mypy · GitHub
Open Graph Title: Moving an overloaded generic function into a class can sometimes introduce "incompatible return type" errors · Issue #5510 · python/mypy
X Title: Moving an overloaded generic function into a class can sometimes introduce "incompatible return type" errors · Issue #5510 · python/mypy
Description: Consider the following function: from typing import * T = TypeVar('T') @overload def f1(x: int) -> int: ... @overload def f1(x: T) -> T: ... def f1(*args, **kwargs): pass This program, after #5476 is merged, will type-check with no error...
Open Graph Description: Consider the following function: from typing import * T = TypeVar('T') @overload def f1(x: int) -> int: ... @overload def f1(x: T) -> T: ... def f1(*args, **kwargs): pass This program, after #5476 ...
X Description: Consider the following function: from typing import * T = TypeVar('T') @overload def f1(x: int) -> int: ... @overload def f1(x: T) -> T: ... def f1(*args, **kwargs): pass This program...
Opengraph URL: https://github.com/python/mypy/issues/5510
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Moving an overloaded generic function into a class can sometimes introduce \"incompatible return type\" errors","articleBody":"Consider the following function:\r\n\r\n```python\r\nfrom typing import *\r\n\r\nT = TypeVar('T')\r\n\r\n@overload\r\ndef f1(x: int) -> int: ...\r\n@overload\r\ndef f1(x: T) -> T: ...\r\ndef f1(*args, **kwargs): pass\r\n```\r\n\r\nThis program, after https://github.com/python/mypy/pull/5476 is merged, will type-check with no errors.\r\n\r\nBut if we move that function into a class like so, it'll cause an \"Overloaded function signatures 1 and 2 overlap with incompatible return types\" errors:\r\n\r\n```python\r\nclass Wrapper(Generic[T]):\r\n @overload\r\n def f2(self, x: int) -> int: ...\r\n @overload\r\n def f2(self, x: T) -> T: ...\r\n def f2(self, *args, **kwargs): pass\r\n```\r\n\r\nIt seems this is because mypy is inferring `f2` to basically be structured like below:\r\n\r\n```python\r\nclass Dummy(Generic[T]): pass\r\n\r\n@overload\r\ndef f3(d: Dummy[T], x: int) -> int: ...\r\n@overload\r\ndef f3(d: Dummy[T], x: T) -> T: ...\r\ndef f3(*args, **kwargs): pass\r\n```\r\n\r\nBasically, it's surprising that converting the function/tweaking the generics in what seems like a harmless way introduces a new error message. This is probably a bug?\r\n\r\nIn any case, it's unclear what the right thing to do here is -- I'm creating this issue so we can keep track of this issue + link to it in in the overload tests.\r\n\r\nAlso see https://github.com/python/mypy/pull/5280#discussion_r200473173 for a little more context.","author":{"url":"https://github.com/Michael0x2a","@type":"Person","name":"Michael0x2a"},"datePublished":"2018-08-20T05:17:40Z","url":"https://github.com/python/mypy/issues/5510"}
| 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:2d10bbcc-6ac7-2def-6dd3-b593aea1e489 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9EF0:14A3EB:1320220:1902946:6B0005A3 |
| html-safe-nonce | d71c9efca9a53037dea6ae1b1efa31f7139c8487a79e129cd39ec571e1d1b322 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUYwOjE0QTNFQjoxMzIwMjIwOjE5MDI5NDY6NkIwMDA1QTMiLCJ2aXNpdG9yX2lkIjoiNzcwNzAyOTA2MzA4ODQ3MzUwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f6ac491afbec0c8b0539daa9eb28bb0e6a811497b30ef34e3270b0ddc70971e2 |
| hovercard-subject-tag | issue:351988164 |
| 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/5510/issue_layout |
| twitter:image | https://opengraph.githubassets.com/588cc86f23dad07cce1c40020269a04c9bfadfd7ed589795b66e68c1efc9856c/python/mypy/issues/5510 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/588cc86f23dad07cce1c40020269a04c9bfadfd7ed589795b66e68c1efc9856c/python/mypy/issues/5510 |
| og:image:alt | Consider the following function: from typing import * T = TypeVar('T') @overload def f1(x: int) -> int: ... @overload def f1(x: T) -> T: ... def f1(*args, **kwargs): pass This program, after #5476 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Michael0x2a |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width