title: Warn for every (nested) function with free variables (recursively)
body: <p>I'd like to do the following:</p>
  
  <pre><code>for every nested function f anywhere in this_py_file:
      if has_free_variables(f):
          print warning
  </code></pre>
  
  <p>Why? Primarily as insurance against the late-binding closure gotcha as <a href="http://docs.python-guide.org/en/latest/writing/gotchas/#late-binding-closures">described elsewhere</a>. Namely:</p>
  
  <pre><code>&gt;&gt;&gt; def outer():
  ...     rr = []
  ...     for i in range(3):
  ...         def inner():
  ...             print i
  ...         rr.append(inner)
  ...     return rr
  ... 
  &gt;&gt;&gt; for f in outer(): f()
  ... 
  2
  2
  2
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>And whenever I get warned about a free variable, I would either add an explicit exception (in the rare case that I would want this behaviour) or fix it like so:</p>
  
  <pre>
  ...         def inner(<b>i=i</b>):
  </pre>
  
  <p>Then the behaviour becomes more like nested classes in Java (where any variable to be used in an inner class has to be <code>final</code>).</p>
  
  <p>(As far as I know, besides solving the late-binding issue, this will also promote better use of memory, because if a function "closes over" some variables in an outer scope, then the outer scope cannot be garbage collected for as long as the function is around. Right?)</p>
  
  <p>I can't find any way to get hold of functions nested in other functions. Currently, the best way I can think of is to instrument a parser, which seems like a lot of work.</p>