Title: False positive when type checking overloads with generics · Issue #9023 · python/mypy · GitHub
Open Graph Title: False positive when type checking overloads with generics · Issue #9023 · python/mypy
X Title: False positive when type checking overloads with generics · Issue #9023 · python/mypy
Description: Are you reporting a bug, or opening a feature request? Bug MyPy has some strange behavior when type-checking overloaded functions with multiple generic parameters. Example from typing import Callable, TypeVar, Union, overload T = TypeVar...
Open Graph Description: Are you reporting a bug, or opening a feature request? Bug MyPy has some strange behavior when type-checking overloaded functions with multiple generic parameters. Example from typing import Callab...
X Description: Are you reporting a bug, or opening a feature request? Bug MyPy has some strange behavior when type-checking overloaded functions with multiple generic parameters. Example from typing import Callab...
Opengraph URL: https://github.com/python/mypy/issues/9023
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False positive when type checking overloads with generics","articleBody":"Are you reporting a bug, or opening a feature request? **Bug**\r\n\r\nMyPy has some strange behavior when type-checking overloaded functions with multiple generic parameters.\r\n\r\n## Example\r\n```\r\nfrom typing import Callable, TypeVar, Union, overload\r\n\r\nT = TypeVar('T')\r\nU = TypeVar('U')\r\n\r\n@overload\r\ndef call(*, f: Callable[[], T]) -> T: ...\r\n\r\n@overload\r\ndef call(*, u: U) -> U: ...\r\n\r\ndef call(*, f: Callable[[], T] = None, u: U = None) -> Union[T, U, None]:\r\n return f() if f else u\r\n```\r\n\r\n## Actual behavior\r\n```\r\n$ mypy example.py\r\nexample.py:12: error: Overloaded function implementation does not accept all possible arguments of signature 2\r\nexample.py:12: error: Overloaded function implementation cannot produce return type of signature 2\r\nFound 2 errors in 1 file (checked 1 source file)\r\n```\r\n\r\nIf I swap the order of the parameters on line 12 then mypy complains about signature 1 instead of signature 2.\r\n```\r\ndef call(*, u: U = None, f: Callable[[], T] = None) -> Union[T, U, None]:\r\n```\r\n\r\nI can get mypy to accept the module by adding a dummy parameter in signature 2:\r\n```\r\ndef call(*, f: None = None, u: U) -> U: ...\r\n```\r\n\r\n## Expected behavior\r\n```\r\n$ mypy example.py\r\nSuccess: no issues found in 1 source file\r\n```\r\n\r\n## Versions\r\n```\r\n$ mypy --version\r\nmypy 0.780\r\n$ python3 --version\r\nPython 3.8.1\r\n```\r\nDo you see the same issue after installing mypy from Git master? **Yes**","author":{"url":"https://github.com/ngaya-ll","@type":"Person","name":"ngaya-ll"},"datePublished":"2020-06-19T04:11:55Z","url":"https://github.com/python/mypy/issues/9023"}
| 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:9e0f68c9-3ed8-90d5-6702-48107ec3f671 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E36:B1603:24431E6:2F354D6:6AFFF173 |
| html-safe-nonce | cb0ae3daee6be33e40476e9c97d7150513eb5688bb9ff10fceab2a15e3408d4e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTM2OkIxNjAzOjI0NDMxRTY6MkYzNTRENjo2QUZGRjE3MyIsInZpc2l0b3JfaWQiOiIzNjAyMTAyMDU2OTEyOTQxNDI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bdafda57d99381cacd0be3b7e86f76cb8c552a61baefc6cb46d0a8e16620589a |
| hovercard-subject-tag | issue:641690373 |
| 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/9023/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f9387172c219239c83f37545f49c041c51357b71b10c687b896956d71468778f/python/mypy/issues/9023 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f9387172c219239c83f37545f49c041c51357b71b10c687b896956d71468778f/python/mypy/issues/9023 |
| og:image:alt | Are you reporting a bug, or opening a feature request? Bug MyPy has some strange behavior when type-checking overloaded functions with multiple generic parameters. Example from typing import Callab... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ngaya-ll |
| 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