I found this today while looking at a library for an API .
def my_function(self, required_param=None):
assert(required_param)
... Do cool function stuff
Wouldn't it be easier to do this:
def my_function(self, required_param):
... Do cool function stuff
Or, am I missing something?
The assert()
of course gives you one unified exception that could come up, but unless you wanted this function to fail silently to do something in that case, wouldn't you rather have it break loudly so that you can catch such errors early on? I've never understood why people use assertions in production code. Perhaps, I will after I get some answers for this.