[Python-ideas] If branch merging

Nick Coghlan ncoghlan at gmail.com
Wed Jun 10 01:46:03 CEST 2015


On 10 Jun 2015 05:00, "Wolfram Hinderer" <wolfram.hinderer at googlemail.com>
wrote:

>>
>>
> Hm, that's my point, isn't it?
> The evaluation of subscript() happens after the evaluation of value().
> The object that the RHS evaluates to (i.e. value()) is determined before
subscript() is evaluated. Sideeffects of subscript() may mutate this
object, but can't change *which* object is assigned.
> But if
>
>
>     x[(a.b as b)] = b
>
> means
>
>     b = a.b
>     x[b] = b

That would be:

    x[b] = (a.b as b)

> then the evaluation of the LHS *does* change which object is assigned.
That's why I asked for clarification.

Execution order wouldn't change, so it would mean the following:

    _temp = b
    b = a.b
    x[b] = _temp

This means you'd get the potentially surprising behaviour where the name
binding would still happen even if the subscript assignment fails.

However if name bindings *didn't* leak out of their containing expression
by default, and while/if/elif code generation instead gained machinery to
retrieve the name bindings for any named subexpressions in the condition,
that would eliminate most of the potentially bizarre edge cases.

Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150610/6d178cf2/attachment.html>


More information about the Python-ideas mailing list