Title: Mypy is still too eager about outer context · Issue #5874 · python/mypy · GitHub
Open Graph Title: Mypy is still too eager about outer context · Issue #5874 · python/mypy
X Title: Mypy is still too eager about outer context · Issue #5874 · python/mypy
Description: Consider this example: T = TypeVar('T') S = TypeVar('S') def add(x: List[T], y: List[S]) -> List[Union[T, S]]: ... a: List[int] b: List[str] e: List[Union[int, str]] = add(a, b) It fails on the last line with the following (I skip invari...
Open Graph Description: Consider this example: T = TypeVar('T') S = TypeVar('S') def add(x: List[T], y: List[S]) -> List[Union[T, S]]: ... a: List[int] b: List[str] e: List[Union[int, str]] = add(a, b) It fails on the las...
X Description: Consider this example: T = TypeVar('T') S = TypeVar('S') def add(x: List[T], y: List[S]) -> List[Union[T, S]]: ... a: List[int] b: List[str] e: List[Union[int, str]] = add(a, b) ...
Opengraph URL: https://github.com/python/mypy/issues/5874
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypy is still too eager about outer context","articleBody":"Consider this example:\r\n```python\r\nT = TypeVar('T')\r\nS = TypeVar('S')\r\n\r\ndef add(x: List[T], y: List[S]) -\u003e List[Union[T, S]]: ...\r\n\r\na: List[int]\r\nb: List[str]\r\n\r\ne: List[Union[int, str]] = add(a, b)\r\n```\r\nIt fails on the last line with the following (I skip invariance notes):\r\n```\r\nerror: Argument 1 to \"add\" has incompatible type \"List[int]\"; expected \"List[Union[int, str]]\"\r\nerror: Argument 2 to \"add\" has incompatible type \"List[str]\"; expected \"List[Union[int, str]]\"\r\n```\r\nIf I remove the annotation for `e`, everything works fine.\r\n\r\nWhen previously working on the external context issues, I found that I don't like how constrains for unions against unions are inferred (not that they are wrong, just counterintuitive). For example, `Union[T, S] \u003c: Union[str, int]` infers `T \u003c : Union[str, int] and S \u003c: Union[str, int]`, which is technically fine, but leads to errors like above.\r\n\r\nThis blocks https://github.com/python/mypy/pull/5873","author":{"url":"https://github.com/ilevkivskyi","@type":"Person","name":"ilevkivskyi"},"datePublished":"2018-11-08T15:58:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/5874/mypy/issues/5874"}
| 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:5559016c-5566-f5b1-f493-be532251fb43 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D174:2293D:488194:68AB73:6A62063C |
| html-safe-nonce | 3f15218de1d210499464d441fd5c77503c1bc44270e85cf2db031f78effe4d47 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTc0OjIyOTNEOjQ4ODE5NDo2OEFCNzM6NkE2MjA2M0MiLCJ2aXNpdG9yX2lkIjoiMzU4Nzg3NDc4ODc1NjAzMTAzNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 62b88470a41d06ca687b006d231d51b75681fb3091499eb84a18974a7bd77540 |
| hovercard-subject-tag | issue:378797217 |
| 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/5874/issue_layout |
| twitter:image | https://opengraph.githubassets.com/43495c68a0b77e189b36a03d263d85063a9671f196e3f01bdd4e06cdeb6658d1/python/mypy/issues/5874 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/43495c68a0b77e189b36a03d263d85063a9671f196e3f01bdd4e06cdeb6658d1/python/mypy/issues/5874 |
| og:image:alt | Consider this example: T = TypeVar('T') S = TypeVar('S') def add(x: List[T], y: List[S]) -> List[Union[T, S]]: ... a: List[int] b: List[str] e: List[Union[int, str]] = add(a, b) It fails on the las... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ilevkivskyi |
| hostname | github.com |
| expected-hostname | github.com |
| None | be9a4d9589756e22b427637ffbf1123a96e067050e57f5cec403e3080a650ca4 |
| 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 | 7b5509702f01f876c214a2cbb142690847de0019 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width