Closed
Description
Feature request:
Make it possible to tell mypy to treat the following as errors:
if None:
pass
if 1:
pass
if [1, 2, 3]:
pass
if "asdf":
pass
class A:
def __bool__(self):
return True
a = A()
if a:
pass
(This list is based on the "Truth Value Testing" section in https://docs.python.org/3/library/stdtypes.html)
The goal is to force the developer to use explicit coercions like:
if x is not None:
pass
if x != 0:
pass
if len(x) > 0:
pass
if bool(x):
pass
Of course libraries and stubs should not be affected by this restriction.
The rationale is that while truth value testing is a valuable shortcut for many people, it also causes bugs, so some projects might want to force their developers to use explicit coercions.