> > Might it make more sense to issue a warning at compile time to the effect
> > that a variable is being used before it's assigned? How completely are
>> Hard to make sure, so, it would always be "MIGHT be used before
> assignment". E.g.,
>> def f():
> for i in range(6):
> if i>0: print x,
> x = str(i)
>> this is OK... no UnboundNameError. Now, change the if's guard to
> if SolveTuringHaltingProblem(i): print x,
> to see why it's hard to make sure about this at compile time.
>> A warning might still be OK of course, even though it may need to
> be worded in wishy-washy "might" terms -- this IS peculiar usage.
GCC warns about this stuff as soon as there's a path through the code
that could leave a variable unassigned, even if the path may not be
reachable depending on what other functions do, and while it
occasionally caused my to insert a useless initialization, I've
usually found that it was hard enough to prove to myself that the
initialization was unneeded to make me happy to insert it.
--Guido van Rossum (home page: http://www.python.org/~guido/)