Title: Recognize comparison with Ellipsis · Issue #2180 · python/mypy · GitHub
Open Graph Title: Recognize comparison with Ellipsis · Issue #2180 · python/mypy
X Title: Recognize comparison with Ellipsis · Issue #2180 · python/mypy
Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Open Graph Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
X Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Opengraph URL: https://github.com/python/mypy
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Recognize comparison with Ellipsis","articleBody":"Consider the following program:\n\n```\nimport builtins\nfrom typing import Any, Optional, Union\n\ndef func1() -> Optional[str]:\n multi_state = 'value' # type: Optional[str]\n if multi_state is None:\n return None\n reveal_type(multi_state)\n return multi_state\n\ndef func2() -> Any:\n multi_state = 'value' # type: Union[str, builtins.ellipsis]\n if multi_state is Ellipsis:\n return None\n reveal_type(multi_state)\n return multi_state\n\nfunc1()\nfunc2()\n```\n\nIf I typecheck with:\n\n```\n$ mypy --strict-optional --suppress-error-context test_recognize_ellipsis_comparison.py\n```\n\nI get:\n\n```\ntest_recognize_ellipsis_comparison.py:8: error: Revealed type is 'builtins.str'\ntest_recognize_ellipsis_comparison.py:15: error: Revealed type is 'Union[builtins.str, builtins.ellipsis]'\n```\n\nBut expect:\n\n```\ntest_recognize_ellipsis_comparison.py:8: error: Revealed type is 'builtins.str'\ntest_recognize_ellipsis_comparison.py:15: error: Revealed type is 'builtins.str'\n```\n\nThis suggests that mypy does not recognize the comparison `value is Ellipsis` in the same way that it recognizes `value is None`.\n\nIn my own codebase having explicit recognition for Ellipsis would be useful in some functions that use both None and Ellipsis as sentinel values.\n","author":{"url":"https://github.com/davidfstr","@type":"Person","name":"davidfstr"},"datePublished":"2016-09-24T22:05:01Z","url":"https://github.com/python/mypy/issues/2180"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:1eb9716c-4fd0-6636-bd04-633a8da996f4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 830C:382035:40D985:5A5C2E:6B007038 |
| html-safe-nonce | e4e8c82325172576838f5c461b4cfd6cac0f618da59ed1405176125ee477fcf9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzBDOjM4MjAzNTo0MEQ5ODU6NUE1QzJFOjZCMDA3MDM4IiwidmlzaXRvcl9pZCI6Ijg3NjQ4MTE0MzI4NjE2NTkxOTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9a02a57bae65be089a271802f532d6d546605da7b96e75894771340d7ac0b199 |
| hovercard-subject-tag | repository:7053637 |
| 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/python/mypy/issues/2180 |
| twitter:image | https://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy |
| og:image:alt | Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| turbo-cache-control | no-cache |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width