Yeah, but in practice you rarely (if ever) call foo() with a literal. In normal code you'll use variables or return values, and if they're annotated, mypy will catch mismatching types.
What you propose will certainly solve the issue when dealing with unannotated code, though.
Yes exactly, mypy will catch mismatching types.
But in my example I do not have mismatching types, but still can detect an issue when testing a function which expects `Optional[float]` only with an `int`.
Regarding literals or annotated variables: mypy will detect mismatching types in both cases.
Comments
Yeah, but in practice you rarely (if ever) call foo() with a literal. In normal code you'll use variables or return values, and if they're annotated, mypy will catch mismatching types.
What you propose will certainly solve the issue when dealing with unannotated code, though.
Yes exactly, mypy will catch mismatching types. But in my example I do not have mismatching types, but still can detect an issue when testing a function which expects `Optional[float]` only with an `int`.
Regarding literals or annotated variables: mypy will detect mismatching types in both cases.