Given a Python function definition of the form:
def foo(a=None, b=1, c='bar'):
How can I dynamically determine which parameters have been set to a value different than their default value? For instance:
foo(48)
I want to be able to dynamically identify that a
was the only parameter that was set. The solution I'm seeking would continue to work even if I added additional parameters to the signature (i.e. I don't want to do a manual check if a == None
, etc.).
==UPDATE==
To clarify my goal:
For some users of function foo, I allow it to be executed regardless. If I identify that user is of user type/class/category Bar then I only want to allow it to succeed only if they called foo
with an argument for parameter a
. If they provided arguments (or at least, arguments not equal to the defaults) for any other parameter then an Exception should be raised. (I know which user is calling the function based on other global data).
Again, I could simply say if b != 1 or c != 'bar'
, but then I would have to update it every time foo
's signature gets modified.