
On Mon, Nov 1, 2021 at 5:03 AM Brendan Barnwell <brenbarn@brenbarn.net> wrote:
On 2021-10-31 05:57, Chris Angelico wrote:
Deferred expressions are not the same as late-bound argument defaults.
You keep saying this, but I still don't get the point. Descriptors are not the same as properties, but we can implement properties with descriptors. Decorators are not the same as callables, but we can implement decorators with callables. The plus sign is not the same as an __add__ method, but we can define the implementation of + in terms of __add__ (and __radd__) methods on objects.
As far as I can tell the only real difference is that you seem very intent on the idea that the default argument is ONLY evaluated right at the beginning of the function and not later. But so what? A general deferred expression would still allow you to do that, it would just also allow you to evaluate the deferred expression at some other point. That might be useful or it might not, but I don't see how it prevents a deferred object from serving the function of a late-bound default. The question isn't whether deferred objects and late-bound defaults "are the same", but whether one can provide a more general framework within which the other can be expressed.
The whole point of deferred expressions is the time delay, but function defaults have to be evaluated immediately upon entering the function. You're contorting all manner of things to try to come up with something that would work, and the result is, in my opinion, quite inelegant; it doesn't do everything that function defaults need to, requires inordinate amounts of code to accomplish simple tasks, and makes implications that are entirely unnecessary. Deferred expressions of various kinds are certainly possible, but they are not a useful implementation of argument defaults, due to those exact contortions. ChrisA