title: del in Python functions deleting variable before the line?
body: <p>Consider the following code:</p>
  
  <pre><code>foo=None
  def bar():
      print(foo, flush=True) # UnboundLocalError
      print('MARK')
      del foo
  
  print(foo)
  bar()
  #print(foo)
  </code></pre>
  
  <p>Basically I have a function that calls del in it. However, when I run the program, I get <code>UnboundLocalError</code> for that <code>'foo' referenced before assignment</code>. If I comment out the <code>del</code> line, the exception is gone. I suppose the del should be called exactly on the line it is on, so that the variable is invalidated only after that. But it doesn't seem to be the case.</p>
  
  <p>Is this expected behavior? (Specifically, I'm using Python 3.6.2)</p>