Remove Redundant If Statements
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: remove-redundant-if
Section titled “Sourcery refactoring id: remove-redundant-if”Description:
Section titled “Description:”Removes conditional tests where the conditional is always True or False
Before:
Section titled “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:
Section titled “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:
Section titled “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