Title: [1.20 regression] False positive for checking reachability on dict with single-variant enum keys · Issue #21409 · python/mypy · GitHub
Open Graph Title: [1.20 regression] False positive for checking reachability on dict with single-variant enum keys · Issue #21409 · python/mypy
X Title: [1.20 regression] False positive for checking reachability on dict with single-variant enum keys · Issue #21409 · python/mypy
Description: Bug Report After upgrading from 1.19.x to 1.20.x, I'm seeing a false positive with reachability checking for dicts with single-variant Enum keys. To Reproduce https://mypy-play.net/?mypy=latest&python=3.12&flags=warn-unreachable&gist=3ba...
Open Graph Description: Bug Report After upgrading from 1.19.x to 1.20.x, I'm seeing a false positive with reachability checking for dicts with single-variant Enum keys. To Reproduce https://mypy-play.net/?mypy=latest&pyt...
X Description: Bug Report After upgrading from 1.19.x to 1.20.x, I'm seeing a false positive with reachability checking for dicts with single-variant Enum keys. To Reproduce https://mypy-play.net/?mypy=latest...
Opengraph URL: https://github.com/python/mypy/issues/21409
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[1.20 regression] False positive for checking reachability on dict with single-variant enum keys","articleBody":"**Bug Report**\nAfter upgrading from 1.19.x to 1.20.x, I'm seeing a false positive with reachability checking for `dict`s with single-variant `Enum` keys.\n\n**To Reproduce**\n\nhttps://mypy-play.net/?mypy=latest&python=3.12&flags=warn-unreachable&gist=3ba2a6f89ea69ebf0ce78f0d91fb0e7f\n\n```py\nimport enum\n\nclass Color(enum.Enum):\n RED = enum.auto()\n\ndef foo(colors: list[Color]) -> None:\n counts: dict[Color, int] = {}\n for color in colors:\n if color not in counts:\n counts[color] = 0 # error: Statement is unreachable [unreachable]\n counts[color] += 1\n```\n\nIf I [add a second `Enum` variant](https://mypy-play.net/?mypy=1.20.2&python=3.12&flags=warn-unreachable&gist=3ab07115fc955b11e27bf639c337cd8c), the error goes away.\n\nInterestingly, the error also goes away if I [remove the explicit type annotation](https://mypy-play.net/?mypy=1.20.2&python=3.12&flags=warn-unreachable&gist=8fad802fc75f8f5db0dae53f1a297352).\n\n**Expected Behavior**\n\n[With v1.19.1](https://mypy-play.net/?mypy=1.19.1&python=3.12&flags=warn-unreachable&gist=3ba2a6f89ea69ebf0ce78f0d91fb0e7f), I get no errors.","author":{"url":"https://github.com/kmurphy4","@type":"Person","name":"kmurphy4"},"datePublished":"2026-05-05T02:37:23Z","url":"https://github.com/python/mypy/issues/21409"}
| 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:e8409b82-c3de-23c2-f46f-1849d32541d2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D2C6:2F0104:17FE859:1FD4A85:6B002ADD |
| html-safe-nonce | fe1dfb6bb1252103b7811d3712f1e55e73ed3fb6977cff1fc06e44cd5b916f1c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMkM2OjJGMDEwNDoxN0ZFODU5OjFGRDRBODU6NkIwMDJBREQiLCJ2aXNpdG9yX2lkIjoiMjc4NTgxMjkzMzU1MTA3NDAxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 19e204ff2036cde35a88da8082f54e21598e95ca9db0a7bae770e3fdc7a1bc87 |
| hovercard-subject-tag | issue:4381095021 |
| 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/21409/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d1c9003f691f4a9de1ae8af809f52e46d03e3eeb9e05e26feffecd92813a880e/python/mypy/issues/21409 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d1c9003f691f4a9de1ae8af809f52e46d03e3eeb9e05e26feffecd92813a880e/python/mypy/issues/21409 |
| og:image:alt | Bug Report After upgrading from 1.19.x to 1.20.x, I'm seeing a false positive with reachability checking for dicts with single-variant Enum keys. To Reproduce https://mypy-play.net/?mypy=latest&pyt... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kmurphy4 |
| 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