How to use the astor.source_repr.pretty_source function in astor

To help you get started, we’ve selected a few astor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / tangent / tangent / quoting.py View on Github external
def to_source(node, indentation=' ' * 4):
  """Return source code of a given AST."""
  if isinstance(node, gast.AST):
    node = gast.gast_to_ast(node)
  generator = SourceWithCommentGenerator(indentation, False,
                                         astor.string_repr.pretty_string)
  generator.visit(node)
  generator.result.append('\n')
  return astor.source_repr.pretty_source(generator.result).lstrip()
github zylo117 / tensorflow-gpu-macosx / tensorflow / contrib / autograph / pyct / compiler.py View on Github external
def ast_to_source(node, indentation='  '):
  """Return the source code of given AST."""
  if isinstance(node, gast.AST):
    node = gast.gast_to_ast(node)
  generator = astor.codegen.SourceGenerator(indentation, False,
                                            astor.string_repr.pretty_string)
  generator.visit(node)
  generator.result.append('\n')
  # In some versions of Python, literals may appear as actual values. This
  # ensures everything is string.
  code = map(str, generator.result)
  return astor.source_repr.pretty_source(code).lstrip()