module documentation

Part of the astor library for Python AST manipulation. License: 3-clause BSD Copyright 2012-2015 (c) Patrick Maupin Copyright 2013-2015 (c) Berker Peksag Utilities for node (and, by extension, tree) manipulation. For a whole-tree approach, see the treewalk submodule.

Class ExplicitNodeVisitor This expands on the ast module's NodeVisitor class to remove any implicit visits.
Class NonExistent This is not the class you are looking for.
Function allow_ast_comparison This ugly little monkey-patcher adds in a helper class to all the AST node types. This helper class allows eq/ne comparisons to work, so that entire trees can be easily compared by Python's comparison machinery...
Function dump_tree Dumps an AST or similar structure:
Function fast_compare This is optimized to compare two AST trees for equality. It makes several assumptions that are currently true for AST trees used by rtrip, and it doesn't examine the _attributes.
Function iter_node Iterates over an object:
Function strip_tree Strips an AST by removing all attributes not in _fields.
def allow_ast_comparison(): (source)

This ugly little monkey-patcher adds in a helper class to all the AST node types. This helper class allows eq/ne comparisons to work, so that entire trees can be easily compared by Python's comparison machinery. Used by the anti8 functions to compare old and new ASTs. Could also be used by the test library.

def dump_tree(node, name=None, initial_indent='', indentation=' ', maxline=120, maxmerged=80, iter_node=iter_node, special=ast.AST, list=list, isinstance=isinstance, type=type, len=len): (source)

Dumps an AST or similar structure: - Pretty-prints with indentation - Doesn't print line/column/ctx info

def fast_compare(tree1, tree2): (source)

This is optimized to compare two AST trees for equality. It makes several assumptions that are currently true for AST trees used by rtrip, and it doesn't examine the _attributes.

def iter_node(node, name='', unknown=None, list=list, getattr=getattr, isinstance=isinstance, enumerate=enumerate, missing=NonExistent): (source)

Iterates over an object: - If the object has a _fields attribute, it gets attributes in the order of this and returns name, value pairs. - Otherwise, if the object is a list instance, it returns name, value pairs for each item in the list, where the name is passed into this function (defaults to blank). - Can update an unknown set with information about attributes that do not exist in fields.

def strip_tree(node, iter_node=iter_node, special=ast.AST, list=list, isinstance=isinstance, type=type, len=len): (source)

Strips an AST by removing all attributes not in _fields. Returns a set of the names of all attributes stripped. This canonicalizes two trees for comparison purposes.