Order of clause in one-line if/else statement yields different mypy behaviors #8519
Labels
bug
mypy got something wrong
topic-join-v-union
Using join vs. using unions
topic-ternary-expression
a if b else c
I may have encountered a bug in Mypy's inference of types when using a one-line if/else statement:
The issue appears when returning a lambda function or a standard built-in (in that case
print
), depending on abool
.^^^ The above raises the following Mypy error:
Incompatible return value type (got "function", expected "Callable[..., None]")
However, reversing the condition like below does not show any error.
This somehow suggests that mypy is using the type of the
if
block to infer the return type? I'm not sure whether this is intended or indeed a bug.Meta information
0.761
mypy.ini
The text was updated successfully, but these errors were encountered: