Remove Redundant If Statements
Sourcery refactoring id: remove-redundant-if
Description:
Removes conditional tests where the conditional is always True
or False
Before:
def hello(name: str):
if name.startswith("L"):
self.sing("Hip Hip Horray! For " + name)
elif not name.startswith("L"):
self.sing("Hello " + name + ", it's nice to meet you.")
After:
def hello(name: str):
if name.startswith("L"):
self.sing("Hip Hip Horray! For " + name)
else:
self.sing("Hello " + name + ", it's nice to meet you.")
Explanation:
This refactoring will re-structure conditionals where Sourcery determines that
one of the tests is always True
or False
. This reveals the actual logic of
the conditional to the reader, making the code easier to understand.
See also: remove-redundant-boolean