module documentation

Part of the astor library for Python AST manipulation. License: 3-clause BSD Copyright (c) 2008 Armin Ronacher Copyright (c) 2012-2017 Patrick Maupin Copyright (c) 2013-2017 Berker Peksag This module converts an AST into Python source code. Before being version-controlled as part of astor, this code came from here (in 2012): https://gist.github.com/1250562

Class Delimit A context manager that can add enclosing delimiters around the output of a SourceGenerator method. By default, the parentheses are added, but the enclosed code may set discard=True to get rid of them.
Class SourceGenerator This visitor is able to transform a well formed syntax tree into Python sourcecode.
Function precedence_setter This only uses a closure for performance reasons, to reduce the number of attribute lookups. (set_precedence is called a lot of times.)
Function to_source This function can convert a node tree back into python sourcecode. This is useful for debugging purposes, especially if you're dealing with custom asts not generated by python itself.
Variable set_precedence Undocumented
def precedence_setter(AST=ast.AST, get_op_precedence=get_op_precedence, isinstance=isinstance, list=list): (source)

This only uses a closure for performance reasons, to reduce the number of attribute lookups. (set_precedence is called a lot of times.)

def to_source(node, indent_with=' '*4, add_line_information=False, pretty_string=pretty_string, pretty_source=pretty_source, source_generator_class=None): (source)

This function can convert a node tree back into python sourcecode. This is useful for debugging purposes, especially if you're dealing with custom asts not generated by python itself. It could be that the sourcecode is evaluable when the AST itself is not compilable / evaluable. The reason for this is that the AST contains some more data than regular sourcecode does, which is dropped during conversion. Each level of indentation is replaced with `indent_with`. Per default this parameter is equal to four spaces as suggested by PEP 8, but it might be adjusted to match the application's styleguide. If `add_line_information` is set to `True` comments for the line numbers of the nodes are added to the output. This can be used to spot wrong line number information of statement nodes. `source_generator_class` defaults to `SourceGenerator`, and specifies the class that will be instantiated and used to generate the source code.

set_precedence = (source)

Undocumented