Ir al contenido

Deep nesting (ARCH2184)

Esta página aún no está disponible en tu idioma.

Key python.quality.deep-nesting · Severity warning · Category quality

Deeply nested if/for/while blocks make code hard to follow. Flatten the nesting with early-return guard clauses.

def handle(user):
if user:
if user.active:
if user.has_role("admin"):
return do_work()
return None
def handle(user):
if not user or not user.active:
return None
if not user.has_role("admin"):
return None
return do_work()

Flatten the nesting by returning early for invalid states.