Title: Type narrowing for ellipsis via 'is ...' failing in 1.9.0 · Issue #17002 · python/mypy · GitHub
Open Graph Title: Type narrowing for ellipsis via 'is ...' failing in 1.9.0 · Issue #17002 · python/mypy
X Title: Type narrowing for ellipsis via 'is ...' failing in 1.9.0 · Issue #17002 · python/mypy
Description: Bug Report As of mypy 1.9.0, narrowing of unions containing EllipsisType via the expressions if x is ... or if x is Ellipsis no longer works. In both branches of the if statement, the type of x still contains EllipsisType instead of bein...
Open Graph Description: Bug Report As of mypy 1.9.0, narrowing of unions containing EllipsisType via the expressions if x is ... or if x is Ellipsis no longer works. In both branches of the if statement, the type of x sti...
X Description: Bug Report As of mypy 1.9.0, narrowing of unions containing EllipsisType via the expressions if x is ... or if x is Ellipsis no longer works. In both branches of the if statement, the type of x sti...
Opengraph URL: https://github.com/python/mypy/issues/17002
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type narrowing for ellipsis via 'is ...' failing in 1.9.0","articleBody":"**Bug Report**\r\n\r\nAs of mypy 1.9.0, narrowing of unions containing `EllipsisType` via the expressions `if x is ...` or `if x is Ellipsis` no longer works. In both branches of the if statement, the type of `x` still contains `EllipsisType` instead of being narrowed.\r\n\r\nThis narrowed as expected in 1.8.0.\r\n\r\nAs a workaround, it appears that `if instanceof(x, EllipsisType)` still works as expected.\r\n\r\n**To Reproduce**\r\n\r\nRun mypy against the following snippet:\r\n\r\n```python\r\nfrom types import EllipsisType\r\n\r\nx: int | EllipsisType\r\n\r\nif x is ...:\r\n pass\r\nelse:\r\n y = x + 1\r\n```\r\n\r\nA more complicated reproduction of this issue can be seen in our repo here: https://github.com/lsst/daf_butler/actions/runs/8209898890/job/22456322445?pr=973\r\n\r\n**Expected Behavior**\r\n\r\nmypy 1.8.0 shows no errors because `x` was narrowed to `int` in the else clause:\r\n```\r\nSuccess: no issues found in 1 source file\r\n```\r\n\r\n**Actual Behavior**\r\nmypy 1.9.0 reports an error instead:\r\n\r\n```\r\ntmp.py:8: error: Unsupported operand types for + (\"EllipsisType\" and \"int\") [operator]\r\ntmp.py:8: note: Left operand is of type \"int | EllipsisType\"\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 1.9.0\r\n- Mypy command-line flags: none\r\n- Mypy configuration options from `mypy.ini` (and other config files): none\r\n- Python version used: 3.11.7\r\n","author":{"url":"https://github.com/dhirving","@type":"Person","name":"dhirving"},"datePublished":"2024-03-08T23:54:17Z","url":"https://github.com/python/mypy/issues/17002"}
| 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:0f4b76e6-ea88-6afe-e3b7-8c53df72ba56 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8CF2:77A5A:31BD594:42197D8:6B003855 |
| html-safe-nonce | 217a485f49e108d39a9be897bf7e20eafd7c3788f2edfeec5e47ae9bf8937f35 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0YyOjc3QTVBOjMxQkQ1OTQ6NDIxOTdEODo2QjAwMzg1NSIsInZpc2l0b3JfaWQiOiIxNjQyOTM4MjM3OTE3ODcwMTY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3f3c6a3921df1ac298d9d30db774ac15ec70984fc4229795eafbe0ce147e6a3d |
| hovercard-subject-tag | issue:2176935503 |
| 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/17002/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b573d89e9209e303efc322b6c2a69b5441c0c5b70c5d1b87f0c0ccb871fdb794/python/mypy/issues/17002 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b573d89e9209e303efc322b6c2a69b5441c0c5b70c5d1b87f0c0ccb871fdb794/python/mypy/issues/17002 |
| og:image:alt | Bug Report As of mypy 1.9.0, narrowing of unions containing EllipsisType via the expressions if x is ... or if x is Ellipsis no longer works. In both branches of the if statement, the type of x sti... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dhirving |
| 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