-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugmypy got something wrongmypy got something wrong
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 in practice.
The helper looks like this:
def unwrap[T](optional: T | None) -> T:
if optional is None:
raise ValueError()
return optionalAs 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.
My suspicion is this is related to #17427, but I have not performed a bisect.
To Reproduce
Expected Behavior
I would expect the type to update to just not include None.
Actual Behavior
Type is changed to Never.
Your Environment
- Mypy version used: mypy 1.12, mypy 1.13, mypy master branch
- Python version used: 3.12
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong