Title: [1.16 regression] no longer recognizes enum singleton as only possible case · Issue #19271 · python/mypy · GitHub
Open Graph Title: [1.16 regression] no longer recognizes enum singleton as only possible case · Issue #19271 · python/mypy
X Title: [1.16 regression] no longer recognizes enum singleton as only possible case · Issue #19271 · python/mypy
Description: I have an enum class Raise that has a single member, Raise._. I use this as a pattern to indicate that a function argument, if not specified, will default to raising an exception. Essentially it serves as an alternative to None, which a ...
Open Graph Description: I have an enum class Raise that has a single member, Raise._. I use this as a pattern to indicate that a function argument, if not specified, will default to raising an exception. Essentially it se...
X Description: I have an enum class Raise that has a single member, Raise._. I use this as a pattern to indicate that a function argument, if not specified, will default to raising an exception. Essentially it se...
Opengraph URL: https://github.com/python/mypy/issues/19271
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[1.16 regression] no longer recognizes enum singleton as only possible case","articleBody":"I have an enum class `Raise` that has a single member, `Raise._`. I use this as a pattern to indicate that a function argument, if not specified, will default to raising an exception. Essentially it serves as an alternative to `None`, which a caller might want to explicitly pass. The following used to work in 1.15 but 1.16 complains.\n\n```\nfrom enum import Enum\nfrom os import environ\nfrom typing import final, TypeVar, Union\n\n\n@final # 1.16 fails with or without this.\nclass Raise(Enum):\n '''\n A singleton value to indicate that the default behavior is to raise an exception.\n '''\n _ = 0\n\n\ndef get_some_config_val(default:str|Raise=Raise._) -> str:\n '''\n Get some config value or return the default. If default is not specified,\n then raise an exception.\n '''\n try:\n return environ['SOME_CONFIG_VAL']\n except KeyError:\n if default is Raise._: raise\n return default\n```\n\nIn 1.15 it appears that that mypy understood that `Raise._` was the only value of type `Raise`. In 1.16 that returns `error: Incompatible return value type (got \"str | Raise\", expected \"str\") [return-value]`.\n\nNote that originally I did not have the `@final` decoration. After some reading I am unsure whether or not it should be required for this example to work, but it does not seem to affect the behavior of either 1.15 or 1.16. It would seem that the @final should be necessary for mypy to recognize that `Raise._` is the only possible value of type `Raise`, unless it was proving to itself that there is no subclass of `Raise`.\n\nObviously, I can change the implementation to `if is instance(Raise._, Raise): raise`, but there is an apparent loss of sophistication in 1.16 so I thought it was worth reporting.\n\n\n```\nPython 3.13.3\nmypy 1.16.0 (compiled: yes)\n```\n","author":{"url":"https://github.com/gwk","@type":"Person","name":"gwk"},"datePublished":"2025-06-10T16:01:38Z","url":"https://github.com/python/mypy/issues/19271"}
| 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:a58cabbc-8c7d-5d10-ba46-ec689867d1e7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A05E:CEC0A:2E3B2E7:3D252BA:6B002402 |
| html-safe-nonce | 51978f8c447ebb8f086eb5e678cc9f9642a322e1a5ff7f3e4e78e9a0498a296e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDVFOkNFQzBBOjJFM0IyRTc6M0QyNTJCQTo2QjAwMjQwMiIsInZpc2l0b3JfaWQiOiIzNDk2NDc0NzEwNzI2NjgxNjAyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f18ec9a23ec2bc36049d50394c623cf33b787774c7a6fd73646009b869a5a8f6 |
| hovercard-subject-tag | issue:3134140317 |
| 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/19271/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8c21a498e5481f7f0c85bec2044e2ef85461b59eb11c18b9bf91d91aedda5a1e/python/mypy/issues/19271 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8c21a498e5481f7f0c85bec2044e2ef85461b59eb11c18b9bf91d91aedda5a1e/python/mypy/issues/19271 |
| og:image:alt | I have an enum class Raise that has a single member, Raise._. I use this as a pattern to indicate that a function argument, if not specified, will default to raising an exception. Essentially it se... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gwk |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width