[Python-Dev] What's the status of PEP 505: None-aware operators?
Eric Fahlgren
ericfahlgren at gmail.com
Thu Nov 30 11:08:43 EST 2017
On Thu, Nov 30, 2017 at 2:48 AM, Andrea Griffini <agriff at tin.it> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171130/ea28c765/attachment.html>
More information about the Python-Dev
mailing list