[Python-Dev] restrictions on global statement

Guido van Rossum guido@python.org
Mon, 01 Apr 2002 21:14:17 -0500

> 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/)