[Python-ideas] Globalize lonely augmented assignment

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Jun 13 02:19:38 CEST 2010

Georg Brandl wrote:

>    a += b   is equivalent to
>    a = a.__iadd__(b)

It's not quite the same as that, because if a stands for an
indexed expression, the index is only evaluated once.

> With the proposal, it would be much more complicated and dependent on
> the context: "... it's the same as <code>, but if the name would only
> be made a local by augmented assignment statements, it's automatically
> made nonlocal if there's a matching non-local binding, or global
> otherwise."

It doesn't have to be as complicated as that -- you only need
to add something like "except that if the LHS is a bare name,
it does not imply that the name is local." Any context-dependent
effects then follow from the existing scope rules.


More information about the Python-ideas mailing list