Empty and Implicit Returns cause resiliency issues.

Production RiskSoftware ResiliencyCode Reliability

Empty and Implicit Returns cause resiliency issues.

This code insight

Counts one violation each time a function has at least one significant return (expression different from nothing, none or false) and in the same time :

  •  at least one empty return
    OR
  • an implicit return in place of the last statement.

bad

def foo(x):
if x >= 0:
return math.sqrt(x)
# <— implicit return here

def bar(x):
if x < 0:
return # <—- empty return here
return math.sqrt(x)

good

def foo(x):
if x >= 0:
return math.sqrt(x)
else:
return Nonedef bar(x):
if x < 0:
return None
return math.sqrt(x)

5362

Why you should care

Be consistent in return statements. Either all return statements in a function should return an expression, or none of them should. If any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None , and an explicit return statement should be present at the end of the function (if reachable).

Business Impacts

Production Risk

CAST recommendations

References

5362

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.

See featuresHow it works