Sometimes I find myself writing Python code that looks like this:
def check_stuff(param): if condition1(param): return "condition1" # These might be enum values, etc., instead of strings if condition2(param): return "condition2" def func(param): cs = check_stuff(param) if "condition1" == cs: raise Exception1(param) if "condition2" == cs: raise Exception2(param) #... Here, the return value of check_stuff is only used to decide what exception to raise. Let's imagine that this is true of every time I call check_stuff, probably because I only call it once. Would it be better style to just raise the exceptions in check_stuff itself?
def check_stuff2(param): if condition1(param): raise Exception1(param) if condition2(param): raise Exception2(param) def func2(param): check_stuff(param) #...