[Python-Dev] What's the status of PEP 505: None-aware operators?
Andrea Griffini
agriff at tin.it
Fri Dec 1 09:03:19 EST 2017
The PEP says that a None-aware function call operator (e.g. "f?(x, y)")
would break the rule of python that arguments are evaluated before the
function but this is not correct.
In Python the function is evaluated before the arguments (but of course the
CALL is made after the evaluation of the arguments).
A None-aware function call operator ?(...) wouldn't break this order of
evaluation rule: 1) evaluate the function, 2) only if it's not None
evaluate arguments and make the call.
In bytecode the None-aware function call would simply require a extra
"JNONE" to the end...
... evaluate the function ...
JNONE skip
... evaluate arguments ...
CALL n
skip:
Note that I'm not saying this would be a good thing, just that the reason
the PEP uses to dismiss this option is actually wrong because Python
doesn't work the way the PEP says it does.
Andrea
On Fri, Dec 1, 2017 at 11:31 AM, Steven D'Aprano <steve at pearwood.info>
wrote:
> On Thu, Nov 30, 2017 at 11:54:39PM -0500, Random832 wrote:
>
> > The OP isn't confusing anything; it's Eric who is confused. The quoted
> > paragraph of the PEP clearly and unambiguously claims that the sequence
> > is "arguments -> function -> call", meaning that something happens after
> > the "function" stage [i.e. a None check] cannot short-circuit the
> > "arguments" stage. But in fact the sequence is "function -> arguments ->
> > call".
>
> I'm more confused than ever. You seem to be arguing that Python
> functions CAN short-circuit their arguments and avoid evaluating them.
> Is that the case?
>
> If not, then I fail to see the difference between
>
> "arguments -> function -> call"
>
> "function -> arguments -> call"
>
> In *both cases* the arguments are fully evaluated before the function is
> called, and so there is nothing the function can do to delay evaluating
> its arguments.
>
> If this is merely about when the name "function" is looked up, then I
> don't see why that's relevant to the PEP.
>
> What am I missing?
>
>
> --
> Steve
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/
> agriff%40tin.it
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171201/147c0989/attachment.html>
More information about the Python-Dev
mailing list