Skip to content

Files

Latest commit

 

History

History
29 lines (22 loc) · 829 Bytes

inconsistent-return-statements.md

File metadata and controls

29 lines (22 loc) · 829 Bytes

Pattern: Inconsistent return statement

Issue: -

Description

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).

Example of incorrect code:

def mix_implicit_explicit_returns(arg):
	if arg < 10:
		return True
	elif arg < 20:
		return

Example of correct code:

def mix_implicit_explicit_returns(arg):
	if arg < 10:
		return True
	elif arg < 20:
		return None

Further Reading