restrictions on global statement
![](https://secure.gravatar.com/avatar/592e0c207bd3240b34eb4898f56a6a39.jpg?s=120&d=mm&r=g)
The lang ref says: Names listed in a \keyword{global} statement must not be defined as formal parameters or in a \keyword{for} loop control target, \keyword{class} definition, function definition, or \keyword{import} statement. (The current implementation does not enforce the latter two restrictions, but programs should not abuse this freedom, as future implementations may enforce them or silently change the meaning of the program.) While this is all technically correct, the second paragraph is a bit misleading. The only case enforced by the compiler is that a formal parameter can't be declared global. Do we actually care about this rule? The lang ref would be shorter if it were silent on the issue, and it would more closely describe the way Python has behaved as long as I've been using it. Jeremy
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
The lang ref says:
Names listed in a \keyword{global} statement must not be defined as formal parameters or in a \keyword{for} loop control target, \keyword{class} definition, function definition, or \keyword{import} statement.
(The current implementation does not enforce the latter two restrictions, but programs should not abuse this freedom, as future implementations may enforce them or silently change the meaning of the program.)
While this is all technically correct, the second paragraph is a bit misleading. The only case enforced by the compiler is that a formal parameter can't be declared global.
Do we actually care about this rule? The lang ref would be shorter if it were silent on the issue, and it would more closely describe the way Python has behaved as long as I've been using it.
Jeremy
I believe at the time when this was added, we had a good reason for it. But I don't recall what it was. It may have had to do with some tools that do an imperfect parse (e.g. looking for 'class' but not scanning for 'global'). I'm not sure it's worth keeping. --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (2)
-
Guido van Rossum
-
Jeremy Hylton