[Python-ideas] If branch merging

Nick Coghlan ncoghlan at gmail.com
Mon Jun 8 23:26:09 CEST 2015


On 9 June 2015 at 01:24, Wolfram Hinderer
<wolfram.hinderer at googlemail.com> wrote:
> Am 08.06.2015 um 14:38 schrieb Nick Coghlan:
>> On 8 June 2015 at 22:12, Steven D'Aprano <steve at pearwood.info> wrote:
>>
>> [In relation to named subexpressions leaking to the surrounding
>> namespace by default]
>>
>>>> What does "x[(a.b as b)] = b" mean
>>>
>>> surely it simply means the same as:
>>>
>>>     b = a.b
>>>     x[b] = b
>>
>> Right, but it reveals the execution order jumping around in a way that
>> is less obvious in the absence of side effects.
>
> I'm lost. The evaluation order of today (right hand side first)
> would make "x[(a.b as b)] = b" mean
>
>     x[a.b] = b
>     b = a.b
>
> (assuming looking up a.b has no side effects).

That assumption that the LHS evaluation has no side effects is the one
that gets revealed by named subexpressions:

>>> def subscript():
...     print("Subscript called")
...     return 0
...
>>> def value():
...     print("Value called")
...     return 42
...
>>> def target():
...     print("Target called")
...     return [None]
...
>>> target()[subscript()] = value()
Value called
Target called
Subscript called

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list