[Python-Dev] Re: would warnings be appropriate for
probably-misused global statements?
Jeremy Hylton
jeremy@alum.mit.edu
Thu, 7 Nov 2002 11:40:40 -0500
>>>>> "GvR" == Guido van Rossum <guido@python.org> writes:
GvR> Global outside a function would seem easy to detect (at least
GvR> as easy as return outside a function), but you need to be
GvR> careful: in a string passed to the exec statement, one could
GvR> have distinct locals and globals, and then 'global x' outside a
GvR> function would make sense. Also, 'global x' makes sense inside
GvR> a class statement.
IIRC I added a warning/error to the compiler about global at the
module level, but later removed it because it was too hard
(impossible?) to determine whether a block of code was being compiled
to exec or being compiled for the body of a module. Anyone interested
could check the CVS log for compile.c.
GvR> But I'm not excited about this. A similar amount of analysis
GvR> can discover assigning to a variable that's not used. Isn't
GvR> that more useful? Using a name that's not defined anywhere.
GvR> Etc. There are tons of these things. PyChecker watches for
GvR> all of them. I'd prefer to make a project out of integrating
GvR> PyChecker functionality into Python, eventually, rather than
GvR> attacking random things one at a time
I didn't check myself, because I agree with you on this point.
Jeremy