title: Python AST, ast.NodeTransformer ,TypeError: required field 'lineno' missing from stmt
body: <p>I'd be v. gratefull to learn something, usefull, as for now, I've been moving blindly.
  so the problem lays in python's <code>ast.NodeTransformer</code>. I was wondering if one is able to add an function to existing class using this way, and not getting mad. </p>
  
  <p>this is how I proceded so far.</p>
  
  <pre><code>import ast, inspect, cla # cla is a name of class to which we want to add a new function
  
  klass = inspect.getsource(cla)
  tree = ast.parse(klass)
  st = '''def function(): return 1'''
  Foo = ast.parse(st)
  
  class AddFunc(ast.NodeTransformer):
        def visit_ClassDef(self, node):
            return node, node.body + Foo.body
            self.generic_visit(node)
  
  inst = AddFunc()
  stuff = i.visit(tree)
  
  # now the trouble begins, a compiling..
  co = compile(stuff, filename='&lt;ast&gt;', mode='exec')
  
  # i get TypeError: required "lineno" missing from stmt
  </code></pre>
  
  <p>I have tried (unsuccesfully as you could probably guess) to handle this by using
  ast library helper functions <code>ast.fix_missing_locations()</code>,
  and <code>ast.copy_locaction()</code>, but in most cases I've ended up guessing or 
  facing <code>AttributeError</code> by tuple which is inside <code>AddFunc</code> class.
  Have anybody some idea, how to manage this?</p>