title: Local functions in Python
body: <p>In the following Python code, I get an <code>UnboundLocalError</code>. As I understand it, local functions share the local variables of the containing function, but this hardly seems to be the case here. I recognise that <code>a</code> is an immutable value in this context, but that should not be a problem.</p>
  
  <pre><code>def outer():
      a = 0
      def inner():
          a += 1
      inner()
  outer()
  </code></pre>
  
  <p>It would seem that the inner function has received copies of all the references in the parent function, as I do not get the <code>UnboundLocalError</code> exception if the value of <code>a</code> is wrapped in a mutable type.</p>
  
  <p>Is someone able to clarify the behaviour here, and point me to the appropriate Python documentation on this?</p>