<div dir="ltr">Often when programming I run into a situation where it would be nice to have "deferred defaults".  Here is an example of what I mean: <div><div>    </div><div><div>    def subfunction_1(a=2, b=3, c=4):</div><div>        return a+b*c</div><div><br></div><div>    def subfunction_2(d=5, e=6, f=7):</div><div>        return d*e+f</div><div><br></div><div>    def main_function(a=2, b=3, c=4, d=5, e=6, f=7):</div><div>        return subfunction_1(a=a, b=b, c=c) + subfunction_2(d=d, e=e, f=f)</div></div></div><div><br></div><div>Here you can see that I had to redefine the defaults in the main_function.  In larger codebases, I find bugs often arise because defaults are defined in multiple places, and somebody changes them in a lower-level function but fails to realize that they are still defined differently in a higher function.</div><div><br></div><div>The only way I currently see to achieve this is not very nice at all, and completely obfuscates the signature of the function:</div><div><div style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><div><br></div><div>    def main_function(**kwargs):</div><div>        return subfunction_1(**{k: v for k, v in kwargs.items() if k in ['a', 'b', 'c']}) </div><div>               + subfunction_2(**{k: v for k, v in kwargs.items() if k in ['d', 'e', 'f']})</div><div style="font-size:small"><br></div><div style="font-size:small">What I was thinking was a "deferred" builtin that would just allow a lower function to define the value (and raise an exception if anyone tried to use it before it was defined)</div><div style="font-size:small"><br></div><div style="font-size:small"><div>    def main_function(a=deferred, b=deferred, c=deferred, d=deferred, e=deferred, f=deferred):</div><div>        return subfunction_1(a=a, b=b, c=c) + subfunction_2(d=d, e=e, f=f)</div><div><br></div></div><div style="font-size:small">I assume this has been discussed before somewhere, but couldn't find anything on it, so please feel free to point me towards any previous discussion on the topic.  </div></div></div></div>