You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 in practice.
The helper looks like this:
After comparing the playground some more with mypy 1.11, I realize this is not really a regression. The actual regression I've been observing is related to django-stubs now inferring some types to Any | None, which means I need to use my helper more than before.
It has actually never worked with types that includes Any. But I solved it with some use of overload:
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 neverNone
in practice.The helper looks like this:
As of mypy 1.12 we see that, if the type before we try narrowing with our function is
Any
, the resulting type is nowNever
.My suspicion is this is related to #17427, but I have not performed a bisect.
To Reproduce
https://mypy-play.net/?mypy=master&python=3.12&flags=show-traceback%2Cwarn-unreachable&gist=6b15a353aa5a6a39fa16fb13fbc009b3
Expected Behavior
I would expect the type to update to just not include
None
.Actual Behavior
Type is changed to
Never
.Your Environment
The text was updated successfully, but these errors were encountered: