Title: Incorrect handling of unions of generics · Issue #14403 · python/mypy · GitHub
Open Graph Title: Incorrect handling of unions of generics · Issue #14403 · python/mypy
X Title: Incorrect handling of unions of generics · Issue #14403 · python/mypy
Description: This was originally reported in #3644 (comment) from typing import Callable, TypeVar, Generic, Union _U = TypeVar('_U') _T = TypeVar('_T') class Future(Generic[_T]): def __init__(self, t: _T): self._t = t def then(self, fn: Callable[[_T]...
Open Graph Description: This was originally reported in #3644 (comment) from typing import Callable, TypeVar, Generic, Union _U = TypeVar('_U') _T = TypeVar('_T') class Future(Generic[_T]): def __init__(self, t: _T): self...
X Description: This was originally reported in #3644 (comment) from typing import Callable, TypeVar, Generic, Union _U = TypeVar('_U') _T = TypeVar('_T') class Future(Generic[_T]): def __init__(se...
Opengraph URL: https://github.com/python/mypy/issues/14403
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect handling of unions of generics","articleBody":"This was originally reported in https://github.com/python/mypy/issues/3644#issuecomment-825494986\r\n```\r\nfrom typing import Callable, TypeVar, Generic, Union\r\n\r\n_U = TypeVar('_U')\r\n_T = TypeVar('_T')\r\n\r\nclass Future(Generic[_T]):\r\n \r\n def __init__(self, t: _T):\r\n self._t = t\r\n\r\n def then(self, fn: Callable[[_T], Future[_U]]) -> Future[_U]:\r\n return fn(self._t)\r\n \r\n def then2(self, fn: Callable[[_T], _U]) -> Future[_U]:\r\n return Future(fn(self._t))\r\n \r\n def then3(self, fn: Union[Callable[[_T], Future[_U]], Callable[[_T], _U]]) -> Future[_U]:\r\n ret = fn(self._t)\r\n if isinstance(ret, Future):\r\n return ret\r\n else:\r\n return Future(ret)\r\n\r\ndef foo(t: int) -> Future[str]:\r\n return Future(\"str\")\r\n\r\nfut = Future(5)\r\n\r\nreveal_type(fut.then(foo)) # is a Future[str], good\r\n\r\ndef foo2(t: int) -> str:\r\n return \"str\"\r\n \r\nreveal_type(fut.then2(foo2)) # also is a Future[str], good\r\n\r\nreveal_type(fut.then3(foo)) # \u003c\u003c==== error, Future[\u003cnothing>]\r\nreveal_type(fut.then3(foo2)) \r\n```","author":{"url":"https://github.com/hauntsaninja","@type":"Person","name":"hauntsaninja"},"datePublished":"2023-01-06T03:48:49Z","url":"https://github.com/python/mypy/issues/14403"}
| 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:84c7f821-6fd1-0c3d-738d-d1228195f2a6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 900E:30501:486387:6207C5:6B002F18 |
| html-safe-nonce | 68cd7260b7405ee57751eceb3b714eb34374ba93fa62c7b0796a90891577fa49 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDBFOjMwNTAxOjQ4NjM4Nzo2MjA3QzU6NkIwMDJGMTgiLCJ2aXNpdG9yX2lkIjoiMTgyNzU0Nzc3NzgxOTc1MDE2OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d3ab18d940b1388cabef1c84ca675a405a8a50f2902840b1ad214444e31b2c10 |
| hovercard-subject-tag | issue:1521876531 |
| 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/14403/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0f0749e1e3e5f749f0c17b5fa30e743bf1f02c855810d4269a97f81ec7a146f3/python/mypy/issues/14403 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0f0749e1e3e5f749f0c17b5fa30e743bf1f02c855810d4269a97f81ec7a146f3/python/mypy/issues/14403 |
| og:image:alt | This was originally reported in #3644 (comment) from typing import Callable, TypeVar, Generic, Union _U = TypeVar('_U') _T = TypeVar('_T') class Future(Generic[_T]): def __init__(self, t: _T): self... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hauntsaninja |
| 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