Title: isinstance checks cause type declarations to leak from the binder · Issue #1568 · python/mypy · GitHub
Open Graph Title: isinstance checks cause type declarations to leak from the binder · Issue #1568 · python/mypy
X Title: isinstance checks cause type declarations to leak from the binder · Issue #1568 · python/mypy
Description: The problem with this is most easily visible with list comprehensions: lst = [1, 2, 3] # type: List[Union[int, str]] [x if isinstance(x, int) else 0 for x in lst] reveal_type([x for x in [4, 5, 6]]) $ python3 -m mypy ~/test.py test.py:3:...
Open Graph Description: The problem with this is most easily visible with list comprehensions: lst = [1, 2, 3] # type: List[Union[int, str]] [x if isinstance(x, int) else 0 for x in lst] reveal_type([x for x in [4, 5, 6]]...
X Description: The problem with this is most easily visible with list comprehensions: lst = [1, 2, 3] # type: List[Union[int, str]] [x if isinstance(x, int) else 0 for x in lst] reveal_type([x for x in [4, 5, 6]]...
Opengraph URL: https://github.com/python/mypy/issues/1568
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"isinstance checks cause type declarations to leak from the binder","articleBody":"The problem with this is most easily visible with list comprehensions:\n\n``` python\nlst = [1, 2, 3] # type: List[Union[int, str]]\n[x if isinstance(x, int) else 0 for x in lst]\nreveal_type([x for x in [4, 5, 6]])\n```\n\n```\n$ python3 -m mypy ~/test.py\ntest.py:3: error: Revealed type is 'builtins.list[Union[builtins.int, builtins.str]]'\n```\n\nThis happens because of this line in the binder, which always adds the declared type of a variable to the topmost frame whenever a binding for it is pushed: https://github.com/python/mypy/blob/master/mypy/checker.py#L127\n\nThis is obviously a bug, but it's not yet clear what the best way to fix the issue is. The binder is small, but complicated -- perhaps the best fix is it rewrite it in a more understandable/robust way?\n\nThis issue is the reason mypy still has a self-typecheck error with #1562.\n","author":{"url":"https://github.com/ddfisher","@type":"Person","name":"ddfisher"},"datePublished":"2016-05-24T00:51:49Z","url":"https://github.com/python/mypy/issues/1568"}
| 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:164f23ff-8aff-411e-f0e5-f1782b29c6c8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C8DC:2AD163:28DCD4D:37B2B65:6B0049B5 |
| html-safe-nonce | 71d5bceb2c741c676d0b69deafc595588f8f8944c097a972371b2d5e4c9d3212 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOERDOjJBRDE2MzoyOERDRDREOjM3QjJCNjU6NkIwMDQ5QjUiLCJ2aXNpdG9yX2lkIjoiMjI4NTY5MDMwMjkwMTUzNzIwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9f0700953e716b793617f60a857b5f520e6852942e597113aa1e7f9e0c0d38d3 |
| hovercard-subject-tag | issue:156397654 |
| 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/1568/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8484c1ce78a68dbb97f245bb4f0efc9f324805c547bd42558927c02d444ec80c/python/mypy/issues/1568 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8484c1ce78a68dbb97f245bb4f0efc9f324805c547bd42558927c02d444ec80c/python/mypy/issues/1568 |
| og:image:alt | The problem with this is most easily visible with list comprehensions: lst = [1, 2, 3] # type: List[Union[int, str]] [x if isinstance(x, int) else 0 for x in lst] reveal_type([x for x in [4, 5, 6]]... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ddfisher |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width