title: Nested list comprehension scope
body: <p>The best way to explain my question is with an example:</p>
  
  <p>example.py:</p>
  
  <pre><code>class A(object):
      integers = [1, 2, 3]
      singles = [i for i in integers]
  
  class B(object):
      integers = [1, 2, 3]
      pairs = [(i, j) for i in integers for j in integers]
  </code></pre>
  
  <p>When I run this under python 2 it works fine, but under python 3 I get a <code>NameError</code> for class <code>B</code> (but not class <code>A</code>):</p>
  
  <pre class="lang-none prettyprint-override"><code>$ python example.py
  Traceback (most recent call last):
    File "example.py", line 6, in &lt;module&gt;
      class B(object):
    File "example.py", line 8, in B
      pairs = [(i, j) for i in integers for j in integers]
    File "example.py", line 8, in &lt;listcomp&gt;
      pairs = [(i, j) for i in integers for j in integers]
  NameError: global name 'integers' is not defined
  </code></pre>
  
  <p>Why does only class <code>B</code> raise a <code>NameError</code> and why only under Python 3?</p>