On Thu, Nov 30, 2017 at 2:48 AM, Andrea Griffini <[email protected]> wrote:
> 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
>
Next, evaluate the arguments for the next function call.
Call 'g()' with all of its arguments evaluated.
> 12 CALL_FUNCTION 1
>
Call the function that 'f()' returned with its argument ('g()') evaluated.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com