Skip to content

robot.parsing.model.visitor

ModelVisitor

Bases: NodeVisitor, VisitorFinder

NodeVisitor that supports matching nodes based on their base classes.

The biggest difference compared to the standard ast.NodeVisitor <https://docs.python.org/library/ast.html#ast.NodeVisitor>__, is that this class allows creating visit_ClassName methods so that the ClassName is one of the base classes of the node. For example, the following visitor method matches all node classes that extend Statement::

1
2
def visit_Statement(self, node):
    ...

Another difference is that visitor methods are cached for performance reasons. This means that dynamically adding visit_Something methods does not work.

ModelTransformer

Bases: NodeTransformer, VisitorFinder

NodeTransformer that supports matching nodes based on their base classes.

See :class:ModelVisitor for explanation how this is different compared to the standard ast.NodeTransformer <https://docs.python.org/library/ast.html#ast.NodeTransformer>__.