Title: Narrow types using overload information · Issue #4063 · python/mypy · GitHub
Open Graph Title: Narrow types using overload information · Issue #4063 · python/mypy
X Title: Narrow types using overload information · Issue #4063 · python/mypy
Description: mypy can use NoReturn to narrow types of variables, thus enabling us to express some kinds of guards, in the sense of #1203 / #2357, without using any dedicated mechanism. For example from typing import Union, NoReturn, overload @overloa...
Open Graph Description: mypy can use NoReturn to narrow types of variables, thus enabling us to express some kinds of guards, in the sense of #1203 / #2357, without using any dedicated mechanism. For example from typing i...
X Description: mypy can use NoReturn to narrow types of variables, thus enabling us to express some kinds of guards, in the sense of #1203 / #2357, without using any dedicated mechanism. For example from typing i...
Opengraph URL: https://github.com/python/mypy/issues/4063
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Narrow types using overload information","articleBody":"mypy can use `NoReturn` to narrow types of variables, thus enabling us to express some kinds of guards, in the sense of #1203 / #2357, without using any dedicated mechanism. For example\r\n```python\r\nfrom typing import Union, NoReturn, overload\r\n\r\n@overload\r\ndef assert_int(x: int) -> None: ...\r\n@overload\r\ndef assert_int(x: str) -> NoReturn: ...\r\n\r\ndef assert_int(x):\r\n assert isinstance(x, int)\r\n\r\ny: Union[int, str]\r\nassert_int(y)\r\nreveal_type(y) # should be: int; currently Union[int, str]\r\n```\r\nThe same technique could be used to narrow types in conditionals, using only \"always true\" / \"always false\" types (do we already have such things? maybe it requires singleton `True` `False` literal-types). \r\n\r\nNote that unlike simple `isinstance`, this can also be used to correlate two different arguments, test for generic compatibility, etc; it is the responsibility of the programmer to have an actual implementation.","author":{"url":"https://github.com/elazarg","@type":"Person","name":"elazarg"},"datePublished":"2017-10-05T20:56:30Z","url":"https://github.com/python/mypy/issues/4063"}
| 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:1b6e47cc-f2cf-fd28-5a98-7ab4b2bfdabb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B1BC:2714DE:1D298DA:273D722:6B000560 |
| html-safe-nonce | 053c91de4ed7f178ec1c2cd363a3539b9e48bd00a27522d9fb5255b33e2b9efe |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMUJDOjI3MTRERToxRDI5OERBOjI3M0Q3MjI6NkIwMDA1NjAiLCJ2aXNpdG9yX2lkIjoiODUwOTU5MDgzOTYxMjE0NzA0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4a5dbd751ee12dd3e262b4aaf0c8a981eb5f70c3851773ba4fd8360da05d0f2e |
| hovercard-subject-tag | issue:263263639 |
| 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/4063/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b8aec9f946336d6f745ceb1b774b750ea5400eb16db2659325714bf3dfdfd80a/python/mypy/issues/4063 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b8aec9f946336d6f745ceb1b774b750ea5400eb16db2659325714bf3dfdfd80a/python/mypy/issues/4063 |
| og:image:alt | mypy can use NoReturn to narrow types of variables, thus enabling us to express some kinds of guards, in the sense of #1203 / #2357, without using any dedicated mechanism. For example from typing i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | elazarg |
| 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