Consider this code with truthy-bool:
class A:
def method(self) -> bool:
return True # whatever
if (a := A()) and a.method():
print(a)
It will output:
» 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?
CC @ikonst
Consider this code with
truthy-bool:It will output:
Two questions:
(:=) and ..., becauseais not really the main thing we check here?CC @ikonst