class documentation

Generic AST node visitor. This class does not work like ast.NodeVisitor, it only visits statements directly within a body. Also, visitor methods can't return anything.

:See: visitor for more informations.

Class Method get_children Returns the nested nodes in the body of a node.
Method generic_visit Helper method to visit a node by calling visit() on each child of the node. This is useful because this vistitor only visits statements inside .body attribute.

Inherited from PartialVisitor:

Method unknown_departure Called before exiting unknown object types.
Method unknown_visit Called when entering unknown object types.

Inherited from Visitor (via PartialVisitor):

Exception SkipChildren Do not visit any children of the current node. The current node's siblings and depart_... method are not affected.
Exception SkipDeparture Do not call the current node's depart_... method. The current node's children and siblings are not affected.
Exception SkipNode Do not visit the current node's children, and do not call the current node's depart_... method.
Exception SkipSiblings Do not visit any more siblings (to the right) of the current node. The current node's children and its depart_... method are not affected.
Method __init__ Undocumented
Method depart Extend the base depart with extensions.
Method visit Extend the base visit with extensions.
Method walk Traverse a tree of objects, calling the visit() method of visitor when entering each node. (The walkabout() method is similar, except it also calls the depart() method before exiting each objects.)
Method walkabout Perform a tree traversal similarly to walk() (which see), except also call the depart() method before exiting each node.
Instance Variable extensions Undocumented
Exception _TreePruningException Base class for Visitor-related tree pruning exceptions.
@classmethod
def get_children(cls, node: ast.AST) -> Iterable[ast.AST]: (source)

Returns the nested nodes in the body of a node.

def generic_visit(self, node: ast.AST): (source)

Helper method to visit a node by calling visit() on each child of the node. This is useful because this vistitor only visits statements inside .body attribute.

So if one wants to visit ast.Expr children with their visitor, they should include:

    def visit_Expr(self, node:ast.Expr):
        self.generic_visit(node)