title: "local variable referenced before assignment" — only functions?
body: <p>Take the following code:</p>
  
  <pre><code>import something
  
  def Foo():
      something = something.SomeClass()
      return something
  </code></pre>
  
  <p>…this is apparently not valid code:</p>
  
  <pre><code>UnboundLocalError: local variable 'something' referenced before assignment
  </code></pre>
  
  <p>…as the local variable <code>something</code> is created, but not assigned, before the RHS of the <code>=</code> is evaluated. (See, for example, <a href="https://stackoverflow.com/questions/7999519/python-local-variable-referenced-before-assignment-error#comment9787200_7999561">this related answer's comment</a>.) This seems a bit odd to me, but sure, I'll go with it. Now, why is the following valid code?</p>
  
  <pre><code>class Foo(object):
      something = something.SomeClass()
  </code></pre>
  
  <p>My understanding was that the inside of a <code>class</code> definition was essentially a scope:</p>
  
  <blockquote>
    <p>The class’s suite is then executed in a new execution frame (see section Naming and binding), using a newly created local namespace and the original global namespace.</p>
  </blockquote>
  
  <p>So, then, why does that code act differently than that of a function?</p>