[Python-ideas] Globalize lonely augmented assignment

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jun 12 03:59:02 CEST 2010

Demur Rumed wrote:

> I believe it would be simpler to learn that variables are _only_ local 
> if bound with the assignment operator.

I'd be happy with that, but

> I'd like to further the locality of a variable to "A 
> variable is local if, and only if, it is first referenced as the left 
> hand side of an assignment on all code paths."

is a *much* more complicated rule both to learn and comply
with. What happens if this is true for some code paths but
not others? That would probably indicate a mistake, and
having the scope default to global in that case would be
quite dangerous.

For the matter at hand, a compromise might be to raise a
compile-time error if a variable is referenced by an
augmented assignment without either a global declaration
or a plain assignment to the same variable somewhere in
the function.

That would help newbies by explaining more clearly what
the problem is, while not affecting any existing correct


More information about the Python-ideas mailing list