title: How is `x = 42; x = lambda: x` parsed?
body: <p>I was surprised that this assertion fails:</p>
  <pre><code>x = 42
  x = lambda: x
  assert x() == 42
  </code></pre>
  <p>It seems that <code>x</code> ends up recursively referring to itself, so that <code>x()</code>, <code>x()()</code>, etc. are all functions.</p>
  <p>What is the rule used to parse this, and where is this documented?</p>
  <p>By the way (not unexpectedly given the above), the original value of <code>x</code> has no references left after the lambda definition:</p>
  <pre><code>class X:
    def __del__(self): print('deleting')
  
  x = X()
  x = lambda: x  # 'deleting' is printed here
  </code></pre>