This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Andreas Hofmeister
Recipients Andreas Hofmeister
Date 2010-06-21.19:46:37
SpamBayes Score 0.00782941
Marked as misclassified No
Message-id <>
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.

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

Nested function, UnboundLocalError, variable assignment

Thank you for your attention
Date User Action Args
2010-06-21 19:46:39Andreas Hofmeistersetrecipients: + Andreas Hofmeister
2010-06-21 19:46:39Andreas Hofmeistersetmessageid: <>
2010-06-21 19:46:37Andreas Hofmeisterlinkissue9049 messages
2010-06-21 19:46:37Andreas Hofmeistercreate