Issue 5763: scope resolving error (original) (raw)
Consider the following two functions:
def outer(): a = 1 def inner(): print a
inner()
#end outer()
def outer_BUG(): a = 1 def inner(): print a a = 2
inner()
#end outer_BUG()
The first function outer() works as expected (it prints 1), but the second function ends with an UnboundLocalError, which says that the "print a" statement inside inner() function references a variable before assignment. Somehow, the interpreter gets to this conclusion by looking at the next statement (a = 2) and forgets the already present variable a from outer function.
This was observed with python 2.5.4 and older 2.5.2. Other releases were not inspected.
Best regards, Vid