[New-bugs-announce] [issue9049] UnboundLocalError in nested function

Andreas Hofmeister report at bugs.python.org
Mon Jun 21 21:46:39 CEST 2010


New submission from Andreas Hofmeister <andreas.hofmeister at yahoo.de>:

Description:
An unexpected UnboundLocalError is produced when assigning a value to a variable inside a nested function. The first assignment to the variable is in the enclosing function.

Example:
def x():
     a = False
     def y():
         print a
         a = True
     return y

Calling x()() produces an UnboundLocalError on the 'print a' line.
If the 'a = True' line is removed, no error occurs.

Tested with:
  - 2.5.1
  - 2.6.5

Keywords: 
Nested function, UnboundLocalError, variable assignment

Thank you for your attention

----------
components: Interpreter Core
messages: 108306
nosy: Andreas Hofmeister
priority: normal
severity: normal
status: open
title: UnboundLocalError in nested function
type: behavior
versions: Python 2.5, Python 2.6

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


More information about the New-bugs-announce mailing list