too-many-nested-blocks / R1702ΒΆ
Message emitted:
Too many nested blocks (%s/%s)
Description:
Used when a function or a method has too many nested blocks. This makes the code less understandable and maintainable.
Problematic code:
def correct_fruits(fruits):
if len(fruits) > 1: # [too-many-nested-blocks]
if "apple" in fruits:
if "orange" in fruits:
count = fruits["orange"]
if count % 2:
if "kiwi" in fruits:
if count == 2:
return True
return False
Correct code:
def correct_fruits(fruits):
if len(fruits) > 1 and "apple" in fruits and "orange" in fruits:
count = fruits["orange"]
if count % 2 and "kiwi" in fruits and count == 2:
return True
return False
Created by the refactoring checker.