-
Notifications
You must be signed in to change notification settings - Fork 752
Open
Labels
Description
Could you add this rule to pep8? I just updated the official PEP 8 to include this (I'm surprised it wasn't already there):
- 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).
Yes:
def foo(x):
if x >= 0:
return math.sqrt(x)
else:
return None
def bar(x):
if x < 0:
return None
return math.sqrt(x)
No:
def foo(x):
if x >= 0:
return math.sqrt(x)
def bar(x):
if x < 0:
return
return math.sqrt(x)
https://mail.python.org/pipermail/python-dev/2015-April/139054.html
confiq, leonsp, pradeepcheers, ustinov, EscapeLife and 1 more