Title: Invalid type inference for zip in a generic class · Issue #12588 · python/mypy · GitHub
Open Graph Title: Invalid type inference for zip in a generic class · Issue #12588 · python/mypy
X Title: Invalid type inference for zip in a generic class · Issue #12588 · python/mypy
Description: The inferred type is wrong here, after the recent typeshed sync: from typing import TypeVar, Generic, List T = TypeVar('T') class C(Generic[T]): a: List[T] b: List[str] def f(self) -> None: for x, y in zip(self.a, self.b): reveal_type((x...
Open Graph Description: The inferred type is wrong here, after the recent typeshed sync: from typing import TypeVar, Generic, List T = TypeVar('T') class C(Generic[T]): a: List[T] b: List[str] def f(self) -> None: for x, ...
X Description: The inferred type is wrong here, after the recent typeshed sync: from typing import TypeVar, Generic, List T = TypeVar('T') class C(Generic[T]): a: List[T] b: List[str] def f(self) -> No...
Opengraph URL: https://github.com/python/mypy/issues/12588
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Invalid type inference for zip in a generic class","articleBody":"The inferred type is wrong here, after the recent typeshed sync:\r\n```py\r\nfrom typing import TypeVar, Generic, List\r\n\r\nT = TypeVar('T')\r\n\r\nclass C(Generic[T]):\r\n a: List[T]\r\n b: List[str]\r\n\r\n def f(self) -> None:\r\n for x, y in zip(self.a, self.b):\r\n reveal_type((x, y)) # Tuple[Tuple[T`1, builtins.str], builtins.str]\r\n```\r\n\r\nThe correct type would be `Tuple[T, builtins.str]`.\r\n\r\nHere's a self-contained example that doesn't depend on typeshed:\r\n```py\r\nfrom typing import TypeVar, Generic, Iterator, List, Tuple\r\n\r\n_T_co = TypeVar(\"_T_co\", covariant=True)\r\n_T1 = TypeVar(\"_T1\")\r\n_T2 = TypeVar(\"_T2\")\r\nS = TypeVar(\"S\")\r\n\r\nclass Z(Iterator[_T_co]):\r\n def __new__(cls,\r\n __iter1: List[_T1],\r\n __iter2: List[_T2]) -> Z[Tuple[_T1, _T2]]: ...\r\n def __iter__(self: S) -> S: ...\r\n def __next__(self) -> _T_co: ...\r\n\r\nT = TypeVar('T')\r\n\r\nclass C(Generic[T]):\r\n a: List[T]\r\n b: List[str]\r\n\r\n def f(self) -> None:\r\n for x, y in Z(self.a, self.b):\r\n reveal_type((x, y)) # Tuple[Tuple[T`1, builtins.str], builtins.str]\r\n```\r\n\r\nThe behavior is correct if we avoid using a self type with `__iter__`:\r\n```py\r\n def __iter__(self) -> Z[_T_co]: ...\r\n```\r\n\r\nThis happens with some frequency in an internal codebase so this seems important to fix.","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2022-04-14T09:26:23Z","url":"https://github.com/python/mypy/issues/12588"}
| 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:f12e20da-6f53-58b6-985b-bb00d748a7d9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A304:12476C:1B10CC4:23A1DC6:6B00260B |
| html-safe-nonce | d0cae9868afba7cc5e56188b8bc7c31186d3b832edf4542c52b1ea61f7d0c66d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzA0OjEyNDc2QzoxQjEwQ0M0OjIzQTFEQzY6NkIwMDI2MEIiLCJ2aXNpdG9yX2lkIjoiNzg4NzYwODY0ODA2MTQyOTI1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1c5cb79183231d402ee16b64fdd36bf7ec7fb918ac702845214af213b0e7b162 |
| hovercard-subject-tag | issue:1204276921 |
| 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/12588/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d83c2ae42c67766fe5f71e54b42eac8e55d4a2ee4df7f36fbf2bae1a174117ba/python/mypy/issues/12588 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d83c2ae42c67766fe5f71e54b42eac8e55d4a2ee4df7f36fbf2bae1a174117ba/python/mypy/issues/12588 |
| og:image:alt | The inferred type is wrong here, after the recent typeshed sync: from typing import TypeVar, Generic, List T = TypeVar('T') class C(Generic[T]): a: List[T] b: List[str] def f(self) -> None: for x, ... |
| 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 | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width