def write_ast(patched_ast_node):
 result = []
 for child in patched_ast_node.sorted_children:
  if isinstance(child, ast.AST):
   result.append(write_ast(child))
  else:
   result.append(child)
 return ''.join(result)

def write_ast ( patched_ast_node ) : result = [ ] for child in patched_ast_node . sorted_children : if isinstance ( child , ast . AST ) : result . append ( write_ast ( child ) ) else : result . append ( child ) return '' . join ( result )
extract source form a patched ast node with sorted_children field if the node is patched with sorted_children turned off you can use node_region function for obtaining code using module source code .