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
{{ message }}
Repository navigation
Possible truthy-bool false positive with := #15685
» mypy ex.py --enable-error-code=truthy-bool
ex.py:6: error: "ex.a" has type "A" which does not implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
ex.py:6: error: "ex.A" returns "A" which does not implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
Two questions:
Why two errors?
Maybe we should skip this rule completely for (:=) and ..., because a is not really the main thing we check here?
I think it would probably be better to emit one error rather than two here. But I don't think I agree that it's a false positive. The first side of the left operand will always evaluate to True, so you could write the snippet more simply as:
Don't see compelling evidence to special-case (2). This code uses and creatively as a statement separator (since lhs is always true), and I'm not convinced this is idiomatic or common (just browsed over examples in PEP-572 but I might've missed something).
Activity
[-]Possible `thruthy-bool` false positive with `:=`[/-][+]Possible `truthy-bool` false positive with `:=`[/+]AlexWaygood commentedon Jul 15, 2023
I think it would probably be better to emit one error rather than two here. But I don't think I agree that it's a false positive. The first side of the left operand will always evaluate to
True, so you could write the snippet more simply as:ikonst commentedon Jul 15, 2023
Agree with (1), need to look into it.
Don't see compelling evidence to special-case (2). This code uses
andcreatively as a statement separator (since lhs is always true), and I'm not convinced this is idiomatic or common (just browsed over examples in PEP-572 but I might've missed something).Suppress second error message with `:=` and `[truthy-bool]` (python#1…