class documentation

"Visitor" pattern abstract superclass implementation for tree traversals.

Each class has corresponding methods, doing nothing by default; override individual methods for specific and useful behaviour. The visit() method is called by walkabout() upon entering a object, it also calls the depart() method before exiting a object.

The generic methods call "visit_ + objet class name" or "depart_ + objet class name", resp.

This is a base class for visitors whose visit_... & depart_... methods should be implemented for all concrete objets types encountered.

This visitor can be composed by other vistitors, see L{VisitorExt}.

Exception IgnoreNode Comletely stop visiting the current node, extensions will not be run on that node.
Exception SkipChildren Do not visit any children of the current node. The current node's siblings and depart_... method are not affected.
Exception SkipNode Do not visit the current node's children, and do not call the current node's depart_... method. The extensions will still be called.
Class Method get_children Undocumented
Method __init__ Undocumented
Method depart Extend the base depart with extensions.
Method visit Extend the base visit with extensions.
Method walkabout Perform a tree traversal, calling visit() method when entering a node and the depart() method before exiting each node.
Instance Variable extensions Undocumented
Exception _TreePruningException Base class for Visitor-related tree pruning exceptions.
Instance Variable _skipped_nodes Undocumented

Inherited from _BaseVisitor:

Method unknown_departure Called before exiting unknown object types.
Method unknown_visit Called when entering unknown object types.
def get_children(cls, ob: T) -> Iterable[T]: (source)

Undocumented

def __init__(self, extensions: ExtList[T] | None = None): (source)

Undocumented

def depart(self, ob: T): (source)

Extend the base depart with extensions.

def visit(self, ob: T): (source)

Extend the base visit with extensions.

Parameters:
node: The node to visit.
def walkabout(self, ob: T): (source)

Perform a tree traversal, calling visit() method when entering a node and the depart() method before exiting each node.

Takes special care to handle L{_TreePruningException} the following way:

  • If a L{SkipNode} exception is raised inside the main visitor C{visit()} method, the C{depart_*} method on the extensions will still be called.
Parameters
ob:TAn object to walk.
extensions: ExtList[T] = (source)

Undocumented

_skipped_nodes: set[T] = (source)

Undocumented