Title: Any incorrectly inferred for a call to an overloaded function · Issue #1322 · python/mypy · GitHub
Open Graph Title: Any incorrectly inferred for a call to an overloaded function · Issue #1322 · python/mypy
X Title: Any incorrectly inferred for a call to an overloaded function · Issue #1322 · python/mypy
Description: This was reported by Alex Allain. Mypy doesn't give an error for this program even though it should: from typing import TypeVar, overload, List T = TypeVar('T') @overload def f(x: T) -> List[T]: ... @overload def f(x: T, y: int) -> int: ...
Open Graph Description: This was reported by Alex Allain. Mypy doesn't give an error for this program even though it should: from typing import TypeVar, overload, List T = TypeVar('T') @overload def f(x: T) -> List[T]: .....
X Description: This was reported by Alex Allain. Mypy doesn't give an error for this program even though it should: from typing import TypeVar, overload, List T = TypeVar('T') @overload def f(x: T) -&...
Opengraph URL: https://github.com/python/mypy/issues/1322
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Any incorrectly inferred for a call to an overloaded function","articleBody":"This was reported by Alex Allain.\n\nMypy doesn't give an error for this program even though it should:\n\n```\nfrom typing import TypeVar, overload, List\n\nT = TypeVar('T')\n\n@overload\ndef f(x: T) -> List[T]: ...\n@overload\ndef f(x: T, y: int) -> int: pass\n\ndef not_checked(text):\n # type: (str) -> str\n return f(*[]) # no error reported!\n```\n\nMypy infers type `List[None]` for `[]` (which is arguably okay, though a little confusing), and this results in all overload variants matching, which is again okay. Now since multiple overload variants match, mypy incorrectly gives up and infers `Any` as the return type of `f(*[])`, even though in this case we could infer a more precise type: a union of all return types of all overload variants, i.e. `Union[List[None], int]`. Alternatively, mypy could give up and say that the return type is ambiguous, but it's less clear when this would be an okay thing to do (if ever).\n","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2016-04-01T10:35:48Z","url":"https://github.com/python/mypy/issues/1322"}
| 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:774b2ac7-3f76-0edd-2f7f-f91b572984ed |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 906C:CEC0A:27DA93D:3445C4D:6B0005B8 |
| html-safe-nonce | 7c5b130e359b4ac3e802240947941beccc930ed2b3d6af7c6e50883bf1061258 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDZDOkNFQzBBOjI3REE5M0Q6MzQ0NUM0RDo2QjAwMDVCOCIsInZpc2l0b3JfaWQiOiI1NjkwODcyMTEwNDA3MjIyNzEzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d82f71cd5230831f0948e5933f5931f15e79da75263778bec305d924b3bb0d8b |
| hovercard-subject-tag | issue:145145639 |
| 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/1322/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fed0a2302bce5a84b737b48f0684776f115e2de70aa98b9b1a218287cc532e61/python/mypy/issues/1322 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fed0a2302bce5a84b737b48f0684776f115e2de70aa98b9b1a218287cc532e61/python/mypy/issues/1322 |
| og:image:alt | This was reported by Alex Allain. Mypy doesn't give an error for this program even though it should: from typing import TypeVar, overload, List T = TypeVar('T') @overload def f(x: T) -> List[T]: ..... |
| 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