Proposal for new minor syntax

Antoon Pardon antoon.pardon at rece.vub.ac.be
Thu Apr 9 09:32:23 CEST 2015


On 03/28/2015 11:43 AM, Steven D'Aprano wrote:
> On Sat, 28 Mar 2015 08:53 pm, Steven D'Aprano wrote:
>
>
>> It saves typing. It might even allow a micro-optimization in the generated
>> bytecode (see below). 
> Oops, I forgot to include the "see below" bit.
>
> Comparing 
>
> a = a.spam()
>
> a .= spam()
>
>
> the Python compiler could perhaps optimize the second form and avoid needing
> two references to "a" (once for the attribute lookup, once for the
> binding). That's not very exciting when it comes to a simple expression
> like the above, but consider:
>
> a[b][c].d.e[f].g = a[b][c].d.e[f].g.spam()
>
>
> *If* that could be optimized, and I'm not certain it can be, that would be
> an argument in favour of the proposal.

I don't understand why you should doubt this. The optimisation is just
the sames as with augmented operators.

tmp = a[b][c].d.e[f]
tmp.g = tmp.g.spam() 




More information about the Python-list mailing list