Title: [1.12, 1.13] Regression in enum narrowing · Issue #18029 · python/mypy · GitHub
Open Graph Title: [1.12, 1.13] Regression in enum narrowing · Issue #18029 · python/mypy
X Title: [1.12, 1.13] Regression in enum narrowing · Issue #18029 · python/mypy
Description: Bug Report Regression in 1.12. Try to narrowing union between StrEnum (or IntEnum) and Literal no longer works since mypy 1.12.0 To Reproduce Issue can be reproduce with this code sample from typing_extensions import Literal from typing ...
Open Graph Description: Bug Report Regression in 1.12. Try to narrowing union between StrEnum (or IntEnum) and Literal no longer works since mypy 1.12.0 To Reproduce Issue can be reproduce with this code sample from typin...
X Description: Bug Report Regression in 1.12. Try to narrowing union between StrEnum (or IntEnum) and Literal no longer works since mypy 1.12.0 To Reproduce Issue can be reproduce with this code sample from typin...
Opengraph URL: https://github.com/python/mypy/issues/18029
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[1.12, 1.13] Regression in enum narrowing","articleBody":"**Bug Report**\r\n\r\nRegression in 1.12.\r\n\r\nTry to narrowing union between StrEnum (or IntEnum) and Literal no longer works since mypy 1.12.0\r\n\r\n**To Reproduce**\r\nIssue can be reproduce with this code sample\r\n```python\r\nfrom typing_extensions import Literal\r\nfrom typing import Union\r\nfrom enum import StrEnum\r\n\r\nclass Foo(StrEnum):\r\n FOO = 'a'\r\n\r\n\r\ndef foo(a: Union[Foo, Literal['foo']]) -\u003e Foo:\r\n if a == 'foo':\r\n return Foo.FOO\r\n\r\n return a\r\n```\r\n[playground link](https://mypy-play.net/?mypy=1.12.0\u0026python=3.12\u0026gist=19f4a8eaf079d73e704b4bb42e48b2fd)\r\nfailing test can be found [here](https://github.com/Fred-si/mypy/blob/d3b4ef5e5abbf74f7a7002423e50175743f898bf/test-data/unit/check-literal.test#L2988-L3017)\r\n\r\n\r\n**Expected Behavior**\r\nAfter the if branch return, variable type should be narrowed to Foo and mypy should not produce error\r\n\r\n**Actual Behavior**\r\nAfter the if branch return, variable type is considered as \"Union[Foo, Literal['foo']]\" and my\r\n\u003c!-- What went wrong? Paste mypy's output. --\u003e\r\n\r\n**Your Environment**\r\n- Mypy version used: 1.12, 1.13, master\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: all versions from 3.8 to 3.13\r\n\r\n","author":{"url":"https://github.com/Fred-si","@type":"Person","name":"Fred-si"},"datePublished":"2024-10-24T12:14:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/18029/mypy/issues/18029"}
| 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:ec935a77-2d92-244d-8d2a-e17ceed7cc44 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A324:298EBF:2E1FF12:3D7A472:6A652553 |
| html-safe-nonce | 3a7ecf9457da122f3a1df10969b7b9d6a489d92485059b34710582a4e3a5992c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzI0OjI5OEVCRjoyRTFGRjEyOjNEN0E0NzI6NkE2NTI1NTMiLCJ2aXNpdG9yX2lkIjoiNjc2MjU3MTM2ODIxMDE3OTQxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b8487f34d5da3e7a76174fc895aa0ce541dc249b6c54a2849d6db19e6e24f4f6 |
| hovercard-subject-tag | issue:2611397831 |
| 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/18029/issue_layout |
| twitter:image | https://opengraph.githubassets.com/03da231f72391be139428f2244d08ca4a233ee5c9e65f440537dd06ee93ff96e/python/mypy/issues/18029 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/03da231f72391be139428f2244d08ca4a233ee5c9e65f440537dd06ee93ff96e/python/mypy/issues/18029 |
| og:image:alt | Bug Report Regression in 1.12. Try to narrowing union between StrEnum (or IntEnum) and Literal no longer works since mypy 1.12.0 To Reproduce Issue can be reproduce with this code sample from typin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Fred-si |
| hostname | github.com |
| expected-hostname | github.com |
| None | 52c76df668885aaff23b50bdca1fa1ea44ac9c1553e888ebc70ff1e4daa4625b |
| 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 | 309153364422b3c499922d1a2a6404910a58ed8e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width