On 5/1/06, Phillip J. Eby <[EMAIL PROTECTED]> wrote: > While I agree that item #1 is a non-starter, it seems to me that in the > case where the compiler statically knows a name is being bound in the > module's globals, and there is a *non-argument* local variable being bound > in a function body, the odds are quite high that the programmer forgot to > use "global". I could almost see issuing a warning, or having a way to > enable such a warning. > > And for the case where the compiler can tell the variable is accessed > before it's defined, there's definitely something wrong. This code, for > example, is definitely missing a "global" and the compiler could in > principle tell: > > foo = 1 > > def bar(): > foo+=1 > > So I see no problem (in principle, as opposed to implementation) with > issuing a warning or even a compilation error for that code. (And it's > wrong even if the snippet I showed is in a nested function definition, > although the error would be different.) > > If I recall correctly, the new compiler uses a control-flow graph that > could possibly be used to determine whether there is a path on which a > local could be read before it's stored.
Sure. This is a quality of implementation issue. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com