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
If cond: Bool, a: A, and b: B, then mypy thinks (cond and a) or b has type Union[bool, A, B]. But in fact the type should just be Union[A, B]. The only way (cond and a) or b can be a bool is for it to be (cond and a), and for that to be truth-y; but in that case (cond and a) would have type A, and never type bool (from cond).
Activity
rwbarton commentedon Jun 13, 2016
See also discussion at #1698.
With
FalseandTruetypes we could type check this as follows: withcond: bool,a: A,b: B, we first havecond and a: Union[falsey_type(bool), A] = Union[False, A], and then(cond and a) or b: Union[truthy_type(Union[False, A]), B] = Union[A, B].dmoisset commentedon Aug 5, 2016
Just checked that my PR #1989 happens to fix this too
ddfisher commentedon Aug 18, 2016
Fixed by #1989.