Title: Mypy should be careful when using outer context for inference · Issue #4872 · python/mypy · GitHub
Open Graph Title: Mypy should be careful when using outer context for inference · Issue #4872 · python/mypy
X Title: Mypy should be careful when using outer context for inference · Issue #4872 · python/mypy
Description: There are several scenarios, when mypy inference leads to false positives. Namely, if the outer type context (return context) is too wide, mypy uses it and fails immediately. Instead it should try the inner context (argument context) bef...
Open Graph Description: There are several scenarios, when mypy inference leads to false positives. Namely, if the outer type context (return context) is too wide, mypy uses it and fails immediately. Instead it should try ...
X Description: There are several scenarios, when mypy inference leads to false positives. Namely, if the outer type context (return context) is too wide, mypy uses it and fails immediately. Instead it should try ...
Opengraph URL: https://github.com/python/mypy/issues/4872
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypy should be careful when using outer context for inference","articleBody":"There are several scenarios, when mypy inference leads to false positives. Namely, if the outer type context (return context) is too wide, mypy uses it and fails immediately. Instead it should try the inner context (argument context) before giving up. For example:\r\n```python\r\nT = TypeVar('T', bound=Dict[str, Any])\r\n\r\ndef f(arg: T) -> T:\r\n ...\r\ndef outer(x: Mapping[str, Any]) -> None:\r\n ...\r\nd: Dict[str, Any]\r\n\r\nm: Mapping[str, Any] = f(d) # Value of type variable \"T\" of \"f\" cannot be \"Mapping[str, Any]\"\r\nouter(f(d)) # Value of type variable \"T\" of \"f\" cannot be \"Mapping[str, Any]\"\r\n```\r\nThere are similar scenarios with union types, for example:\r\n```python\r\nS = TypeVar('S', bound=int)\r\n\r\ndef g(arg: S) -> Optional[S]:\r\n ...\r\n\r\nx: Optional[int]\r\nx = g(42) # Value of type variable \"S\" of \"g\" cannot be \"Optional[int]\"\r\n```\r\netc. What is interesting, the failure _doesn't_ happen if there are only simple types present in the bound and in the context, to reproduce one needs either generics, union types, or other \"complex\" types.","author":{"url":"https://github.com/ilevkivskyi","@type":"Person","name":"ilevkivskyi"},"datePublished":"2018-04-09T12:30:34Z","url":"https://github.com/python/mypy/issues/4872"}
| 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:29e47927-dafa-9ea7-9b03-7c6fef492cac |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8038:3EE843:175F937:1F811C9:6AFFF14C |
| html-safe-nonce | 0aececeebbbe58b09c176377215241a6218bc78a7d1edb2e7bf1d5e11a35e3ba |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDM4OjNFRTg0MzoxNzVGOTM3OjFGODExQzk6NkFGRkYxNEMiLCJ2aXNpdG9yX2lkIjoiMTAwNTQwNzc1MjYzMTA1MzU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bd794b7c7b9890043672e541c874da86a723a7793559b654da6f1a815d4832da |
| hovercard-subject-tag | issue:312511318 |
| 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/4872/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6bf057b88edaaa47fef22cadf5980a51857222178394bf4843b52c315ef7780b/python/mypy/issues/4872 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6bf057b88edaaa47fef22cadf5980a51857222178394bf4843b52c315ef7780b/python/mypy/issues/4872 |
| og:image:alt | There are several scenarios, when mypy inference leads to false positives. Namely, if the outer type context (return context) is too wide, mypy uses it and fails immediately. Instead it should try ... |
| 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 | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width