Title: Recognize isinstance(a[b], ...)? · Issue #2458 · python/mypy · GitHub
Open Graph Title: Recognize isinstance(a[b], ...)? · Issue #2458 · python/mypy
X Title: Recognize isinstance(a[b], ...)? · Issue #2458 · python/mypy
Description: Consider this fragment: from typing import Union, Dict x = {} # type: Dict[str, Union[int, str]] n = '' if isinstance(x[n], int): reveal_type(x[n]) # E: Revealed type is 'Union[builtins.int, builtins.str]' Perhaps mypy should infer type ...
Open Graph Description: Consider this fragment: from typing import Union, Dict x = {} # type: Dict[str, Union[int, str]] n = '' if isinstance(x[n], int): reveal_type(x[n]) # E: Revealed type is 'Union[builtins.int, builti...
X Description: Consider this fragment: from typing import Union, Dict x = {} # type: Dict[str, Union[int, str]] n = '' if isinstance(x[n], int): reveal_type(x[n]) # E: Revealed type is 'Union[builtins...
Opengraph URL: https://github.com/python/mypy/issues/2458
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Recognize isinstance(a[b], ...)?","articleBody":"Consider this fragment:\r\n\r\n```\r\nfrom typing import Union, Dict\r\n\r\nx = {} # type: Dict[str, Union[int, str]]\r\nn = ''\r\nif isinstance(x[n], int):\r\n reveal_type(x[n]) # E: Revealed type is 'Union[builtins.int, builtins.str]'\r\n```\r\n\r\nPerhaps mypy should infer type `int` for `x[n]` (i.e. put `x[n]` into the conditional type binder). \r\n\r\nThe example can be refactored to type check pretty easily:\r\n\r\n```\r\n...\r\nt = x[n]\r\nif isinstance(t, int):\r\n ...\r\n```\r\n\r\nA slightly more interesting example that is a bit harder to get to type check:\r\n\r\n```\r\n...\r\nif n in x and isinstance(x[n], int):\r\n ...\r\n```\r\n\r\nThis was originally reported by @davire on gitter.","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2016-11-15T15:34:55Z","url":"https://github.com/python/mypy/issues/2458"}
| 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:d09cb33a-f9d2-8dd1-8b4d-002a9ab43989 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 811E:251B51:260D60:3540D0:6B006A62 |
| html-safe-nonce | ec8f98e51a6facbc7a0df59a73aac841e04529bdbaed9f80e384d507461478d9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTFFOjI1MUI1MToyNjBENjA6MzU0MEQwOjZCMDA2QTYyIiwidmlzaXRvcl9pZCI6IjQxODA1MjQzNTA4NDUyNTAxNDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | acc8eac46983119c03412e1c9fe14fc33533bf3eb9e988ccce94d4f21d9ca24f |
| hovercard-subject-tag | issue:189424071 |
| 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/2458/issue_layout |
| twitter:image | https://opengraph.githubassets.com/914c6ec024e3cd418abd6c942bd869880c8a92505cb995a3453bb8faa06b8159/python/mypy/issues/2458 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/914c6ec024e3cd418abd6c942bd869880c8a92505cb995a3453bb8faa06b8159/python/mypy/issues/2458 |
| og:image:alt | Consider this fragment: from typing import Union, Dict x = {} # type: Dict[str, Union[int, str]] n = '' if isinstance(x[n], int): reveal_type(x[n]) # E: Revealed type is 'Union[builtins.int, builti... |
| 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 | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| 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 | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width