Title: Regression in 'unwrapping' optional variables with a function · Issue #18059 · python/mypy · GitHub
Open Graph Title: Regression in 'unwrapping' optional variables with a function · Issue #18059 · python/mypy
X Title: Regression in 'unwrapping' optional variables with a function · Issue #18059 · python/mypy
Description: Bug Report For as long as we've been using mypy, we've had this small helper called 'unwrap' to help us work with variables that are for any reason typed to include None, but we for different reasons know in some context are never None i...
Open Graph Description: Bug Report For as long as we've been using mypy, we've had this small helper called 'unwrap' to help us work with variables that are for any reason typed to include None, but we for different reaso...
X Description: Bug Report For as long as we've been using mypy, we've had this small helper called 'unwrap' to help us work with variables that are for any reason typed to include None, but we for...
Opengraph URL: https://github.com/python/mypy/issues/18059
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Regression in 'unwrapping' optional variables with a function","articleBody":"**Bug Report**\r\n\r\nFor as long as we've been using mypy, we've had this small helper called 'unwrap' to help us work with variables that are for any reason typed to include `None`, but we for different reasons know in some context are never `None` in practice.\r\nThe helper looks like this:\r\n```python3\r\ndef unwrap[T](optional: T | None) -> T:\r\n if optional is None:\r\n raise ValueError()\r\n return optional\r\n```\r\n\r\nAs of mypy 1.12 we see that, if the type before we try narrowing with our function is `Any`, the resulting type is now `Never`.\r\n\r\nMy suspicion is this is related to https://github.com/python/mypy/pull/17427, but I have not performed a bisect.\r\n\r\n**To Reproduce**\r\n\r\nhttps://mypy-play.net/?mypy=master&python=3.12&flags=show-traceback%2Cwarn-unreachable&gist=6b15a353aa5a6a39fa16fb13fbc009b3\r\n\r\n**Expected Behavior**\r\n\r\nI would expect the type to update to just not include `None`.\r\n\r\n**Actual Behavior**\r\n\r\nType is changed to `Never`.\r\n\r\n**Your Environment**\r\n- Mypy version used: mypy 1.12, mypy 1.13, mypy master branch\r\n- Python version used: 3.12\r\n\r\n","author":{"url":"https://github.com/stianjensen","@type":"Person","name":"stianjensen"},"datePublished":"2024-10-28T15:56:02Z","url":"https://github.com/python/mypy/issues/18059"}
| 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:86e51ce6-1d10-3a68-f452-a1ce2e616c22 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C176:251AC0:51D47A:6D278F:6B002EF7 |
| html-safe-nonce | 238ca06009e72f91ada95f2b847a1a4504855b2c6a03ff73544fac92d112fb02 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTc2OjI1MUFDMDo1MUQ0N0E6NkQyNzhGOjZCMDAyRUY3IiwidmlzaXRvcl9pZCI6IjcxOTk3MDgyNDMzNDQ1MDI1MTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 41d0502ae626d72034801830bcefc5b394205d9e665d02dc566bd0045a56e3e7 |
| hovercard-subject-tag | issue:2618839499 |
| 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/18059/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b85a05a8df9f67af687e311f059b9be3c9ae37433e23ad474d6941ef76a68383/python/mypy/issues/18059 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b85a05a8df9f67af687e311f059b9be3c9ae37433e23ad474d6941ef76a68383/python/mypy/issues/18059 |
| og:image:alt | Bug Report For as long as we've been using mypy, we've had this small helper called 'unwrap' to help us work with variables that are for any reason typed to include None, but we for different reaso... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | stianjensen |
| 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