Consider merging collapsible if statements
101 station.latest_level = None
102
103 # Attach new level data (if available)
104 if station.measure_id in measure_id_to_value:105 if isinstance(measure_id_to_value[station.measure_id], float):
106 station.latest_level = measure_id_to_value[station.measure_id]
Description
Nested if
statements can be collapsed into a single if
statement by separating their condition using and
operator.
Merging collapsible if
statements increases the code's readability.
Bad practice
if condition1:
if condition2:
dosomething()
Preferred
if condition1 and condition2:
dosomething()
Exception:
DeepSource will not raise this issue when the nested if
statements have comments in between them, as it could be explaining why the nested if
is in place.