Either all return statements in a function should return an expression, or none of them should.
28np.random.seed(6) # for reproducibility
29
30
31def fetch_levels(station_name, dt, return_date=False): 32 """
33 Function that returns measurements and dates of a specified station since a specified number of days ago.
34
Description
According to PEP8, 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).
Good:
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)
Bad:
def foo(x):
if x >= 0:
return math.sqrt(x)
def bar(x):
if x < 0:
return
return math.sqrt(x)