Title: Unions break with `isinstance()` · Issue #1135 · python/mypy · GitHub
Open Graph Title: Unions break with `isinstance()` · Issue #1135 · python/mypy
X Title: Unions break with `isinstance()` · Issue #1135 · python/mypy
Description: Mypy incorrectly reports two errors in this (python 2) snippet. $ nl -ba /tmp/foo.py 1 import typing 2 3 def foo(value): 4 # type: (typing.Union[unicode, bytes]) -> None 5 if isinstance(value, unicode): 6 return 7 if not isinstance(value...
Open Graph Description: Mypy incorrectly reports two errors in this (python 2) snippet. $ nl -ba /tmp/foo.py 1 import typing 2 3 def foo(value): 4 # type: (typing.Union[unicode, bytes]) -> None 5 if isinstance(value, unic...
X Description: Mypy incorrectly reports two errors in this (python 2) snippet. $ nl -ba /tmp/foo.py 1 import typing 2 3 def foo(value): 4 # type: (typing.Union[unicode, bytes]) -> None 5 if isinstance(value, u...
Mail addresses
notifications@github.com
notifications@github.com
Opengraph URL: https://github.com/python/mypy/issues/1135
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unions break with `isinstance()`","articleBody":"Mypy incorrectly reports two errors in this (python 2) snippet. \n\n```\n$ nl -ba /tmp/foo.py\n 1 import typing\n 2 \n 3 def foo(value):\n 4 # type: (typing.Union[unicode, bytes]) -> None\n 5 if isinstance(value, unicode):\n 6 return\n 7 if not isinstance(value, bytes):\n 8 raise TypeError(\"Expected bytes or unicode; got %r\" % type(value))\n$ PYTHONPATH=. scripts/mypy --py2 /tmp/foo.py\n/tmp/foo.py: note: In function \"foo\":\n/tmp/foo.py:7: error: Argument 1 to \"isinstance\" has incompatible type \"Union[object, object]\"; expected \"object\"\n/tmp/foo.py:8: error: No overload variant of \"type\" matches argument types [Union[\u003cERROR>, \u003cERROR>, \u003cERROR>, \u003cERROR>]]\n```\n\nIf lines 5 and 6 are removed, the errors disappear. If line 7 is replaced with `if True:`, the error on line 8 remains. Replacing `unicode` with `str` and running mypy in py3 mode also makes the errors disappear.\n","author":{"url":"https://github.com/bdarnell","@type":"Person","name":"bdarnell"},"datePublished":"2016-01-17T00:55:40Z","url":"https://github.com/python/mypy/issues/1135"}
| 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:965465e5-6f3d-e97c-f62e-69b937535eaf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BAB2:137B3:1A98C0D:231899E:6B003039 |
| html-safe-nonce | 7cc58f7f57e4e60c7f9f4fc32ba9b6feac83d16a876ddab7f0509f3830328af7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQUIyOjEzN0IzOjFBOThDMEQ6MjMxODk5RTo2QjAwMzAzOSIsInZpc2l0b3JfaWQiOiI0NTc2MDAyNjM3MzU4NDQ0NjAyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3c7d70ae3eb0d13c3423a11e3b710700ed81bdcd15ef232a091946a70a3f3c6d |
| hovercard-subject-tag | issue:127066723 |
| 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/1135/issue_layout |
| twitter:image | https://opengraph.githubassets.com/342fa7a49026a489f205753a34d8ca5eb49187d3d3cff24ad29a6f55320d2791/python/mypy/issues/1135 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/342fa7a49026a489f205753a34d8ca5eb49187d3d3cff24ad29a6f55320d2791/python/mypy/issues/1135 |
| og:image:alt | Mypy incorrectly reports two errors in this (python 2) snippet. $ nl -ba /tmp/foo.py 1 import typing 2 3 def foo(value): 4 # type: (typing.Union[unicode, bytes]) -> None 5 if isinstance(value, unic... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bdarnell |
| 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