Merge-Nested-Ifs
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 rule id: merge-nested-ifs
Section titled “Sourcery rule id: merge-nested-ifs”Description
Section titled “Description”Merge nested if conditions
Before
Section titled “Before”if a: if b: return cif a and b: return cExplanation
Section titled “Explanation”Too much nesting can make code difficult to understand, and this is especially true in Python, where there are no brackets to help out with the delineation of different nesting levels.
Reading deeply nested code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two if conditions can be combined using
and is an easy win.