How python code is interpreted and how much static analysis is there?
<p>I thought python is a interpreted language but as per below code snip, it apparently is not doing exactly what I expect? I did some search on that, and it turns out python will 'declare' a name as local implicitly if there is an assignment for it within the function. So it does do some static analysis while interpreting the code, but my question is by how much?  e.g. as below code shown, wont it also optimise as x=1 is not reachable? do we have more details about how we interpret the code? thanks </p>

<pre><code>x = 10
def f():
    if False: x = 1
    print x
UnboundLocalError: local variable 'x' referenced before assignment
</code></pre>
