Nested scopes, and augmented assignment

Terry Reedy tjreedy at udel.edu
Fri Jul 7 00:15:24 EDT 2006


"Antoon Pardon" <apardon at forel.vub.ac.be> wrote in message 
news:slrneapmfr.at1.apardon at rcpc42.vub.ac.be...
> And if  Nested variables are harmfull,

I don't know if anyone said that they were, but Guido obviously does not 
think so, or he would not have added them.  So skip that.

> what is then the big difference between rebinding them and mutating them

A variable is a name.  Name can be rebound (or maybe not) but they cannot 
be mutated.  Only objects (with mutation methods) can be mutated.  In other 
words, binding is a namespace action and mutation is an objectspace action. 
In Python, at least, the difference is fundamental.

Or, in other other words, do not be fooled by the convenient but incorrect 
abbreviated phrase 'mutate a nested variable'.

> that we should forbid the first and allow the second?

Rebinding nested names is not forbidden; it has just not yet been added 
(see below).

Being able to mutate a mutable object is automatic once you have a 
reference to it.  In other words, it you can read the value, you can mutate 
it (if it is mutable).

> I understand that python evolved and that this sometimes results
> in things that in hindsight could have been done better.

So does Guido.  That is one explicit reason he gave for not choosing any of 
the nunerous proposals for the syntax and semantics of nested scope write 
access.  In the face of anti-consensus among the developers and no 
particular personal preference, he decided, "Better to wait than roll the 
dice and make the wrong, hard to reverse, choice now".  (Paraphrased quote)

>I have to wonder if someone really thought this through at design time

Giving the actual history of, if anything, too many people thinking too 
many different thoughts, this is almost funny.

Recently however, Guido has rejected most proposals to focus attention on 
just a few variations and possibly gain a consensus.  So I think there is 
at least half a chance that some sort of nested scope write access will 
appear in 2.6 or 3.0.

Terry Jan Reedy






More information about the Python-list mailing list