Ah, right, the fix_it(fcn) is a nice idea. It might also be a good idea, if we're making an external library anyway, to have a "deferred" object to avoid overloading "None" (which may mean something else than "differ argument"). I
from deferral import deferrable_args, deferred
@deferrable_args
def subfunction_1(a=2, b=3, c=4):
return a+b*c
@deferrable_args
def subfunction_2(d=5, e=6, f=7):
return d*e+f
def main_function(a=deferred, b=deferred, c=deferred, d=deferred, e=deferred, f=deferred):
return subfunction_1(a=a, b=b, c=c) + subfunction_2(d=d, e=e, f=f)
assert main_function() == (2+3*4)+(5*6+7)
assert main_function(a=8) == (8+3*4)+(5*6+7)
I still think it would be nice to have this as a built-in python feature, for a few reasons:
- When using non-differable functions (say in other codebases), we have to do a bunch of "func = deferrable_args(func)" at the top of the module (or we can just do them at runtime, but then we're doing inspection every time, which is probably slow).
- It adds a layer to the call stack for every deferrable function you're in.
- To avoid annoying errors where you've defined an arg as deferred but forgot to wrap the function in question.