Title: Better messages when type is incompatible due to invariance · Issue #3352 · python/mypy · GitHub
Open Graph Title: Better messages when type is incompatible due to invariance · Issue #3352 · python/mypy
X Title: Better messages when type is incompatible due to invariance · Issue #3352 · python/mypy
Description: Users are often confused by compatibility of invariant collection types. Here is an example from #3351: from typing import List, Union def mean(numbers: List[Union[int, float]]) -> float: return sum(numbers) / len(numbers) some_numbers =...
Open Graph Description: Users are often confused by compatibility of invariant collection types. Here is an example from #3351: from typing import List, Union def mean(numbers: List[Union[int, float]]) -> float: return su...
X Description: Users are often confused by compatibility of invariant collection types. Here is an example from #3351: from typing import List, Union def mean(numbers: List[Union[int, float]]) -> float: return...
Opengraph URL: https://github.com/python/mypy/issues/3352
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Better messages when type is incompatible due to invariance","articleBody":"Users are often confused by compatibility of invariant collection types. Here is an example from #3351:\r\n\r\n```py\r\nfrom typing import List, Union\r\n\r\ndef mean(numbers: List[Union[int, float]]) -> float:\r\n return sum(numbers) / len(numbers)\r\n\r\nsome_numbers = [1, 2, 3, 4]\r\nmean(some_numbers) # Argument 1 to \"mean\" has incompatible type List[int]; \r\n # expected List[Union[int, float]]\r\n```\r\n\r\nIt might be helpful to add a note with more details, since the message doesn't really provide enough context to start googling for help. Here is one idea:\r\n\r\n```\r\nprogram.py:23:note: \"List\" is invariant -- see \u003clink to docs>\r\nprogram.py:23:note: Maybe you can use \"Sequence\" as the target type, which is covariant?\r\n```","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2017-05-10T12:45:08Z","url":"https://github.com/python/mypy/issues/3352"}
| 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:7ff44cc6-7e97-a7e3-a564-bad2b70fa275 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F70:2714DE:1E3934A:28B5FE0:6B000ADB |
| html-safe-nonce | 1252b6ad891920cb6f3b630f08c854194312aaaae737f353abe41428440b12f7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjcwOjI3MTRERToxRTM5MzRBOjI4QjVGRTA6NkIwMDBBREIiLCJ2aXNpdG9yX2lkIjoiNDA0NzUxNjgwMDIyODAxNTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c2c056d539c70e3d222dae9cc8aa0e4b4fc297b4b94eec1a750a5050c0a540a0 |
| hovercard-subject-tag | issue:227667267 |
| 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/3352/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8b784b2f197a185c09de5b7cb2343547ddaea051e3d365040f42e8658bdb371a/python/mypy/issues/3352 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8b784b2f197a185c09de5b7cb2343547ddaea051e3d365040f42e8658bdb371a/python/mypy/issues/3352 |
| og:image:alt | Users are often confused by compatibility of invariant collection types. Here is an example from #3351: from typing import List, Union def mean(numbers: List[Union[int, float]]) -> float: return su... |
| 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