[New-bugs-announce] [issue5763] scope resolving error

vid podpecan report at bugs.python.org
Wed Apr 15 17:10:47 CEST 2009


New submission from vid podpecan <vid.podpecan at gmail.com>:

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

----------
messages: 85992
nosy: vpodpecan
severity: normal
status: open
title: scope resolving error
type: behavior
versions: Python 2.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5763>
_______________________________________


More information about the New-bugs-announce mailing list