Proposal for new minor syntax

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Mar 28 06:43:44 EDT 2015


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.

Still, I'm not entirely convinced that augmented assignments += *= etc are a
good idea or entirely Pythonic, and I'm dubious about pretending that . is
an operator, so I think that overall the proposal would need more
justification than merely "save a bit of typing" and "allow a
micro-optimization".


-- 
Steven




More information about the Python-list mailing list