if-expr-with-true-false (SIM210)
Derived from the flake8-simplify linter.
Fix is sometimes available.
What it does
Checks for if
expressions that can be replaced with bool()
calls.
Why is this bad?
if
expressions that evaluate to True
for a truthy condition an False
for a falsey condition can be replaced with bool()
calls, which are more
concise and readable.
Example
Use instead:
Fix safety
This fix is marked as unsafe because it may change the program’s behavior if the condition does not
return a proper Boolean. While the fix will try to wrap non-boolean values in a call to bool,
custom implementations of comparison functions like __eq__
can avoid the bool call and still
lead to altered behavior. Moreover, the fix may remove comments.