title: Python class scoping rules
body: <p><strong>EDIT:</strong> Looks like this is a very old "bug" or, actually, feature. See, e.g., <a href="https://mail.python.org/pipermail/python-dev/2002-April/023428.html">this mail</a> </p>
  
  <p>I am trying to understand the Python scoping rules. More precisely, I thought that I understand them but then I found this code <a href="http://lackingrhoticity.blogspot.ch/2008/08/4-python-variable-binding-oddities.html">here</a>: </p>
  
  <pre><code>x = "xtop"
  y = "ytop"
  def func():
      x = "xlocal"
      y = "ylocal"
      class C:
          print(x)
          print(y)
          y = 1
  func()
  </code></pre>
  
  <p>In Python 3.4 the output is:</p>
  
  <pre><code>xlocal
  ytop
  </code></pre>
  
  <p>If I replace the inner class by a function then it reasonably gives <code>UnboundLocalError</code>. Could you explain me why it behaves this strange way with classes and what is the reason for such choice of scoping rules?</p>