5 ms·
If you use isinstance(x, (int, float)) instead of type(x) == int then I think you'll find your expected behavior. When you say type narrowing do you mean float
by akubera 8y ago
If you use isinstance(x, (int, float)) instead of type(x) == int then I think you'll find your expected behavior.
When you say type narrowing do you mean floats should be automatically interpreted as int? There is typing.{SupportsInt, SupportsFloat} which can be considered "number" base classes which you may consider as type narrowing. Otherwise if you mean "type of x is known in this if-block" you do get that with `isinstance` type checks (which is the preferred, pythonic way).
I agree that mypy should warn if a NoReturn is assigned; apparently it just ignores typechecking below the NoReturn function call, and is really only used to ensure the NoReturn function is guaranteed to raise before it returns.
- jakear 8y ago`isinstance` is what I wanted for narrowing, thanks!