Title: Make it possible to make Mapping covariant · Issue #738 · python/mypy · GitHub
Open Graph Title: Make it possible to make Mapping covariant · Issue #738 · python/mypy
X Title: Make it possible to make Mapping covariant · Issue #738 · python/mypy
Description: Mapping should be covariant with respect to value, but get() makes it impossible for now, so it's actually invariant. I'd like to have a signature like this for get (we can't use _VT_co in an argument type, as it's covariant): def get(se...
Open Graph Description: Mapping should be covariant with respect to value, but get() makes it impossible for now, so it's actually invariant. I'd like to have a signature like this for get (we can't use _VT_co in an argum...
X Description: Mapping should be covariant with respect to value, but get() makes it impossible for now, so it's actually invariant. I'd like to have a signature like this for get (we can't use _VT_co...
Opengraph URL: https://github.com/python/mypy/issues/738
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make it possible to make Mapping covariant","articleBody":"`Mapping` should be covariant with respect to value, but `get()` makes it impossible for now, so it's actually invariant.\n\nI'd like to have a signature like this for `get` (we can't use `_VT_co` in an argument type, as it's covariant):\n\n```\n def get(self, k: _KT, default: _T = ...) -> Union[_VT_co, _T]: pass\n```\n\nHowever, code like this is currently a problem if we use the above signature:\n\n```\nfrom typing import Dict, List\n\nd = {} # type: Dict[int, List[str]]\na = d.get(1, [])\na.append(2) # Error, type of a is Union[List[str], List[None]], which is bad!\n```\n\nMaybe type inference should use the union return type for the type context of the second argument, since the argument type is an item in the union. This is a little arbitrary but seems safe, and it would fix the above issue, which is probably fairly common. There are probably a bunch of edge cases that need to be considered, but the general idea seems like it could work.\n","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2015-08-09T23:27:02Z","url":"https://github.com/python/mypy/issues/738"}
| 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:c98b34e9-40cb-e0ec-3272-07f2d0477015 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D264:3B60C0:4654B2:5E5D8A:6B002C3A |
| html-safe-nonce | acbe9c91318c9084c591ab84a7b7f03f55132825b76f61c12395965d492a543d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjY0OjNCNjBDMDo0NjU0QjI6NUU1RDhBOjZCMDAyQzNBIiwidmlzaXRvcl9pZCI6IjE2MjM3MDQzODY1MjM5MDA5ODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6451cef8dc786ee0c70cd41ff8b82d7bf06b746b9b9244606953e951793637f7 |
| hovercard-subject-tag | issue:99939832 |
| 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/738/issue_layout |
| twitter:image | https://opengraph.githubassets.com/88adaef8089cc8de82d9d5da2ba78c3ad9fa14c0bcd50940e029b88b3c1aa209/python/mypy/issues/738 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/88adaef8089cc8de82d9d5da2ba78c3ad9fa14c0bcd50940e029b88b3c1aa209/python/mypy/issues/738 |
| og:image:alt | Mapping should be covariant with respect to value, but get() makes it impossible for now, so it's actually invariant. I'd like to have a signature like this for get (we can't use _VT_co in an argum... |
| 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 | 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