Is there a convention for raising errors if the proper combination of key-word arguments is not provided in a function call?
As an example:
def convert(miles=0, kilometers=0):
if miles and not kilometers:
return miles * 1.61
elif kilometers and not miles:
return kilometers / 1.61
else:
raise #exception
In this function, the one or the other parameter must receive an argument; if there are zero or two arguments, the function is invalid.
The built-in exceptions do not include an exception that is obvious for this situation. The option I have considered is TypeError
(used in other bad function calls). Is this the standard way to handle this situation or should I use a different exception?
By the way, I saw this question, but this is not what I am looking for.