[Python-Dev] would warnings be appropriate for probably-misused global statements?

Guido van Rossum guido@python.org
Wed, 06 Nov 2002 13:55:52 -0500


> > I'm starting to think that it might help overcome that 
> > confusion if "global" gave warnings when used in probably-inappropriate ways: 
> > not inside a function, or about a variable that the function does not, in 
> > fact, bind nor re-bind.  Is there agreement that this might be helpful?
> 
> That sounds helpful to me. Essentially you're declaring that it's an
> error (well... warning) to use the global statement in a context where
> it can perform no possible function. And given the name, it's an easy
> mistake for newbies to make... assuming that all "global variables" need
> the "global" statement.

It should be a PyChecker function, definitely.

I'm not sure if Python itself should warn about this.  The needed
analysis isn't easily available (at least not in the current parser).
And there are lots of similar things that we should be warning about,
if we're going to warn about this one.  I'm not prepared (yet) to
incorporate large-scale PyChecker's functionality in the Python
parser.

--Guido van Rossum (home page: http://www.python.org/~guido/)