(original) (raw)
Not really related but the PEP says that arguments in Python are evaluated before the function (as a reason to reject the idea of None-aware function call) but this is not the case:
I think you're missing something here, since it seems clear to me that indeed the arguments are evaluated prior to the function call. Maybe unrolling it would help? This is equivalent to the body of your lambda, and you can see that the argument is evaluated prior to the call which receives it.
>>> func = f()
>>> arg = g()
>>> func(arg)
>>> import dis>>> dis.dis(lambda : f()(g()))1 0 LOAD\_GLOBAL 0 (f)3 CALL\_FUNCTION 0
Call 'f()' with all of its arguments evaluated prior to the call (there are none, that's the '0' on the CALL\_FUNCTION operator).
6 LOAD\_GLOBAL 1 (g)9 CALL\_FUNCTION 0
Call 'g()' with all of its arguments evaluated.
12 CALL\_FUNCTION 1
Call the function that 'f()' returned with its argument ('g()') evaluated.