nodes: 0, module; 1, function_definition; 2, function_name:write_ast; 3, parameters; 4, block; 5, identifier:patched_ast_node; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, return_statement; 10, comment:"""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.
      """; 11, assignment; 12, identifier:child; 13, attribute; 14, block; 15, call; 16, identifier:result; 17, list; 18, identifier:patched_ast_node; 19, identifier:sorted_children; 20, if_statement; 21, attribute; 22, argument_list; 23, call; 24, block; 25, else_clause; 26, string; 27, identifier:join; 28, identifier:result; 29, identifier:isinstance; 30, argument_list; 31, expression_statement; 32, block; 33, identifier:child; 34, attribute; 35, call; 36, expression_statement; 37, identifier:ast; 38, identifier:AST; 39, attribute; 40, argument_list; 41, call; 42, identifier:result; 43, identifier:append; 44, call; 45, attribute; 46, argument_list; 47, identifier:write_ast; 48, argument_list; 49, identifier:result; 50, identifier:append; 51, identifier:child; 52, identifier:child
code: def write_ast(patched_ast_node):
      """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.
      """
      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)