Title: Type inference of Tuples returns object instead · Issue #4975 · python/mypy · GitHub
Open Graph Title: Type inference of Tuples returns object instead · Issue #4975 · python/mypy
X Title: Type inference of Tuples returns object instead · Issue #4975 · python/mypy
Description: While interacting with zip I encountered a variant of the following error: error: No overload variant of "zip" matches argument types [builtins.list[builtins.int*], builtins.object*] which is emitted by mypy on the case of out = list( li...
Open Graph Description: While interacting with zip I encountered a variant of the following error: error: No overload variant of "zip" matches argument types [builtins.list[builtins.int*], builtins.object*] which is emitt...
X Description: While interacting with zip I encountered a variant of the following error: error: No overload variant of "zip" matches argument types [builtins.list[builtins.int*], builtins.object*] whic...
Opengraph URL: https://github.com/python/mypy/issues/4975
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type inference of Tuples returns object instead","articleBody":"While interacting with `zip` I encountered a variant of the following error:\r\n```\r\nerror: No overload variant of \"zip\" matches argument types [builtins.list[builtins.int*], builtins.object*]\r\n```\r\nwhich is emitted by mypy on the case of\r\n```py\r\nout = list(\r\n list(zip([1, 2], ordered_item))\r\n for item in [(1, 2), (4, 5)]\r\n for ordered_item in [item, tuple(reversed(item))]\r\n )\r\nprint(out)\r\n```\r\nThis code runs normally on python 3.6.5, outputting:\r\n```\r\n[[(1, 1), (2, 2)], [(1, 2), (2, 1)], [(1, 4), (2, 5)], [(1, 5), (2, 4)]]\r\n```\r\n\r\n## Expected Behavior\r\nMypy should infer that `ordered_item` is a tuple, or at least an iterable so that `zip` can be applied on it.\r\n\r\nIt may also be interesting to consider the case where `ordered_item` is heterogenous over different `Iterables` (i.e. not only tuples). Would Iterable be inferred then?\r\n\r\n## Actual Behavior\r\nMypy infers the `object` type on `ordered_item` which you understandably cannot zip.\r\n\r\nBy explicitly casting `item` to tuple the error message is resolved:\r\n```py\r\nout = list(\r\n list(zip([1, 2], ordered_item))\r\n for item in [(1, 2), (4, 5)]\r\n for ordered_item in [tuple(item), tuple(reversed(item))]\r\n )\r\nprint(out)\r\n```\r\n\r\n## Environment\r\nOS: macOS 10.13\r\nPython: 3.6.5\r\nmypy: 0.590\r\n","author":{"url":"https://github.com/eddieschoute","@type":"Person","name":"eddieschoute"},"datePublished":"2018-04-26T15:35:38Z","url":"https://github.com/python/mypy/issues/4975"}
| 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:ed68dda2-f2b8-9ecb-b86a-462fb89668e4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BE1C:196792:2E45B2A:3D54790:6B002958 |
| html-safe-nonce | 309c6ad6977cb8871ce467fd110f72f990a32b3071e0e70b7ccda5a804ae4821 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTFDOjE5Njc5MjoyRTQ1QjJBOjNENTQ3OTA6NkIwMDI5NTgiLCJ2aXNpdG9yX2lkIjoiNTIzOTQwNzA2NTQ2OTgyMzMyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8af7c4f1cb294f8bbe8b7e9e6960464a9f85c988797147ccc2b00649762f8e5a |
| hovercard-subject-tag | issue:318085299 |
| 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/4975/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d4e090df0f476d8efebcf85d493f99f5310cb287d009b866f8f57d56bbcf8df5/python/mypy/issues/4975 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d4e090df0f476d8efebcf85d493f99f5310cb287d009b866f8f57d56bbcf8df5/python/mypy/issues/4975 |
| og:image:alt | While interacting with zip I encountered a variant of the following error: error: No overload variant of "zip" matches argument types [builtins.list[builtins.int*], builtins.object*] which is emitt... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | eddieschoute |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width