Assuming a standard get call (like in a dictionary), this should be easy. Define your function with None for the default parameters for your parameters, and then pass color and size without bothering to check!
def apicall(color=None, size=None): pass # Do stuff color = request.GET.get('color') size = request.GET.get('size') apicall(color, size)
This way, you only check None arguments in one place (inside a function call, where you still need to check if the function can be called in several ways). Everything stays beautiful and clean. Of course, this assumes (as I said above) that your get call is similar to the regular Python get dictionary method, which returns None if no value is found.
Finally, I noticed that your apicall function apicall : there is a chance that you actually do not have access to the function code itself. In this case, since you may not know anything about the default values ββfor the function signature, and None may be incorrect, I will probably just write a simple wrapper to check the arguments. You can then invoke the shell as described above.
def wrapped_apicall(color=None, size=None): if color is None and size is None: return apicall()
NOTE. . This second version is not needed if you do not see the code that you are calling and you do not have documentation! Using None as the default argument is very common, so there is a chance that you can just use the first method. I would only use the wrapper method if you cannot change the function you are calling and you do not know what its default arguments are (or its default arguments are modular constants or something, but this is quite rare).
source share