class documentation

class NodeTransformer(NodeVisitor): (source)

Known subclasses: jinja2.optimizer.Optimizer

View In Hierarchy

Walks the abstract syntax tree and allows modifications of nodes. The `NodeTransformer` will walk the AST and use the return value of the visitor functions to replace or remove the old node. If the return value of the visitor function is `None` the node will be removed from the previous location otherwise it's replaced with the return value. The return value may be the original node in which case no replacement takes place.

Method generic_visit Called if no explicit visitor function exists for a node.
Method visit_list As transformers may return lists in some places this method can be used to enforce a list as return value.

Inherited from NodeVisitor:

Method get_visitor Return the visitor function for this node or `None` if no visitor exists for this node. In that case the generic visit function is used instead.
Method visit Visit a node.
def generic_visit(self, node, *args, **kwargs): (source)

Called if no explicit visitor function exists for a node.

Parameters
node:NodeUndocumented
*args:t.AnyUndocumented
**kwargs:t.AnyUndocumented
Returns
NodeUndocumented
def visit_list(self, node, *args, **kwargs): (source)

As transformers may return lists in some places this method can be used to enforce a list as return value.

Parameters
node:NodeUndocumented
*args:t.AnyUndocumented
**kwargs:t.AnyUndocumented
Returns
t.List[Node]Undocumented