On Friday 24 October 2003 12:08 am, Guido van Rossum wrote:
However, as long as we're talking about this stuff, I wish I could write "global foo" at module scope and have that mean "this variable is to be treated as global in all functions in this module".
This is similar to Greg Ewing's proposable to have 'rebindable x' at an outer function scope. My problem with it remains:
It gives outer scopes (some) control over inner scopes. One of the guidelines is that a name defined in an inner scope should always shadow the same name in an outer scope, to allow evolution of the outer scope without affecting local details of inner scope. (IOW if an inner function defines a local variable 'x', the outer scope shouldn't be able to change that.)
I must be missing something, because I don't understand the value of that guideline. I see outer and inner functions as tightly coupled anyway; it's not as if they could be developed independently -- not even lexically, surely not semantically.
I do prefer to have the reminder "this is _assigning_ a NON-local variable" _closer_ to the assignment -- and I DO think it would be great if such rebinding HAD to be an assignment, not some kind of "side effect" from statements such as def, class, for, btw.
(Incidentally, we'd get the latter for free if the nonlocal was "an attribute of some object" -- outer.x = 23 YES, "def outer.x():..." NO. But i'd still feel safer, even with a deuced 'declarative statement', if it could somehow be allowed to rebind nonlocals ONLY with an explicit assignment).
So, anyway, the closer to the assignment the reminder, the better, so if it has to be a "declarative statement" I'd rather have it in the inner function than in the outer one. But for reasons very different from that guideline which I don't grasp... (probably just sleepiness and tiredness on my part...).