Title: type of Union containing Any is incorrectly inferred after an isinstance check · Issue #1720 · python/mypy · GitHub
Open Graph Title: type of Union containing Any is incorrectly inferred after an isinstance check · Issue #1720 · python/mypy
X Title: type of Union containing Any is incorrectly inferred after an isinstance check · Issue #1720 · python/mypy
Description: union_any.py: from typing import Any, Union def func(v): # type: (Union[int, Any]) -> str if isinstance(v, int): s = hex(v) else: s = str(v).lower() return "key:" + s mypy union_any.py: union_any.py: note: In function "func": union_any.p...
Open Graph Description: union_any.py: from typing import Any, Union def func(v): # type: (Union[int, Any]) -> str if isinstance(v, int): s = hex(v) else: s = str(v).lower() return "key:" + s mypy union_any.py: union_any.p...
X Description: union_any.py: from typing import Any, Union def func(v): # type: (Union[int, Any]) -> str if isinstance(v, int): s = hex(v) else: s = str(v).lower() return "key:" + s mypy union_any.py...
Opengraph URL: https://github.com/python/mypy/issues/1720
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"type of Union containing Any is incorrectly inferred after an isinstance check","articleBody":"`union_any.py`:\n\n``` py\nfrom typing import Any, Union\n\ndef func(v):\n # type: (Union[int, Any]) -> str\n if isinstance(v, int):\n s = hex(v)\n else:\n s = str(v).lower()\n return \"key:\" + s\n```\n\n`mypy union_any.py`:\n\n```\nunion_any.py: note: In function \"func\":\nunion_any.py:8: error: No overload variant of \"str\" matches argument types [Union[\u003cERROR>, void]]\n```\n\n`mypy --py2 union_any.py`:\n\n```\nunion_any.py: note: In function \"func\":\nunion_any.py:8: error: Argument 1 to \"str\" has incompatible type \"Union[object, None]\"; expected \"object\"\n```\n\nI discovered this when I used a class which was defined in some library which did not have stubs and I was using `--silent-imports`.\n","author":{"url":"https://github.com/sharmaeklavya2","@type":"Person","name":"sharmaeklavya2"},"datePublished":"2016-06-18T05:09:50Z","url":"https://github.com/python/mypy/issues/1720"}
| 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:091af5f6-0419-53f3-ae2f-e65bc258414a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8918:2F0104:11167AB:167E80E:6B000BA4 |
| html-safe-nonce | 66cdb14b0bf23b9d8c1c227b3f125e57dcd9f74650e167ae97d2a1fd3d1af17e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTE4OjJGMDEwNDoxMTE2N0FCOjE2N0U4MEU6NkIwMDBCQTQiLCJ2aXNpdG9yX2lkIjoiNDczMjk3MjUwMzYzNzQyOTE1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fa0d4b6be2ceed564417ad1ecf6d89711cc4433c913d6b3390333a7dc6c004a4 |
| hovercard-subject-tag | issue:161007424 |
| 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/1720/issue_layout |
| twitter:image | https://opengraph.githubassets.com/01b54c22a5bc3fce8bdc4f07ec09adc4932587e32553d4ea66648c1bdca4a88e/python/mypy/issues/1720 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/01b54c22a5bc3fce8bdc4f07ec09adc4932587e32553d4ea66648c1bdca4a88e/python/mypy/issues/1720 |
| og:image:alt | union_any.py: from typing import Any, Union def func(v): # type: (Union[int, Any]) -> str if isinstance(v, int): s = hex(v) else: s = str(v).lower() return "key:" + s mypy union_any.py: union_any.p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sharmaeklavya2 |
| 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