Title: [2.2 regression] unreachable code regression with custom equality enum membership check · Issue #21703 · python/mypy · GitHub
Open Graph Title: [2.2 regression] unreachable code regression with custom equality enum membership check · Issue #21703 · python/mypy
X Title: [2.2 regression] unreachable code regression with custom equality enum membership check · Issue #21703 · python/mypy
Description: Bug Report Mypy 2.2.0 introduced a regression from 2.1.0 with equality comparisons with custom integer enums. Using the config option warn_unreachable = True, the following code checks successfully in mypy 2.1.0, but under mypy 2.2.0 fai...
Open Graph Description: Bug Report Mypy 2.2.0 introduced a regression from 2.1.0 with equality comparisons with custom integer enums. Using the config option warn_unreachable = True, the following code checks successfully...
X Description: Bug Report Mypy 2.2.0 introduced a regression from 2.1.0 with equality comparisons with custom integer enums. Using the config option warn_unreachable = True, the following code checks successfully...
Opengraph URL: https://github.com/python/mypy/issues/21703
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[2.2 regression] unreachable code regression with custom equality enum membership check","articleBody":"\n**Bug Report**\n\nMypy 2.2.0 introduced a regression from 2.1.0 with equality comparisons with custom integer enums. \n\nUsing the config option `warn_unreachable = True`, the following code checks successfully in mypy 2.1.0, but under mypy 2.2.0 fails with \n```\ntest.py:23: error: Statement is unreachable [unreachable]\n```\ndespite the code actually hitting this path at runtime and printing \"Success\". \n\n\n**To Reproduce**\n\n```python\n#!/usr/bin/env python3\nimport enum\nimport sys\nimport typing\n\nclass E(enum.Enum):\n foo = 1\n bar = 2\n\n def __int__(self) -> int:\n return int(self.value)\n\n def __eq__(self, other: typing.Any) -> bool:\n return bool(int(self) == other)\n\nclass Test:\n def __init__(self) -> None:\n self.val: int = 1\n\nt = Test()\n\nif t.val in [E.foo, E.bar]:\n print(\"success\")\n sys.exit(0)\nprint(\"fail\")\nsys.exit(1)\n```\n\n**Your Environment**\n\n- Mypy version used: 2.2.0\n- Mypy command-line flags: `mypy test.py` \n- Mypy configuration options from `mypy.ini` (and other config files): `warn_unreachable = True`\n- Python version used: 3.11\n","author":{"url":"https://github.com/blbelew","@type":"Person","name":"blbelew"},"datePublished":"2026-07-08T16:14:54Z","url":"https://github.com/python/mypy/issues/21703"}
| 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:a36e9cfb-44db-c11a-c21b-8865d56cd73d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C0E2:3B60C0:406F8C:5693FA:6B002AA7 |
| html-safe-nonce | f7f56b63f0fc5403bb92a280ffc12129ce4e9c75df242a942125a2160ea8222c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMEUyOjNCNjBDMDo0MDZGOEM6NTY5M0ZBOjZCMDAyQUE3IiwidmlzaXRvcl9pZCI6Ijc2OTk2NzMzMzAyOTg2NjE1NDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4eb2ed8865109edcea0f79b91fafe1d75afe49bf36d7f4f8be41c66d97ff56a0 |
| hovercard-subject-tag | issue:4839220181 |
| 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/21703/issue_layout |
| twitter:image | https://opengraph.githubassets.com/96e350dbe165ab7114ef975136e2475005796fda07ce7f3842bd66ec749d0989/python/mypy/issues/21703 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/96e350dbe165ab7114ef975136e2475005796fda07ce7f3842bd66ec749d0989/python/mypy/issues/21703 |
| og:image:alt | Bug Report Mypy 2.2.0 introduced a regression from 2.1.0 with equality comparisons with custom integer enums. Using the config option warn_unreachable = True, the following code checks successfully... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | blbelew |
| 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