rope.base.ast
Classes
A node visitor base class that walks the abstract syntax tree and calls a |
Functions
|
|
|
Pre-order depth-first traversal of AST nodes, calling callback(node) for |
|
Get pre-3.8 ast node name |
|
Module Contents
- rope.base.ast.parse(source, filename='<string>', *args, **kwargs)
- rope.base.ast.call_for_nodes(node, callback)
Pre-order depth-first traversal of AST nodes, calling callback(node) for each node visited.
When each node is visited, callback(node) will be called with the visited node, then its children node will be visited.
If callback(node) returns True for a node, then the descendants of that node will not be visited.
See _ResultChecker._find_node for an example.
- class rope.base.ast.RopeNodeVisitor
Bases:
ast.NodeVisitorA node visitor base class that walks the abstract syntax tree and calls a visitor function for every node found. This function may return a value which is forwarded by the visit method.
This class is meant to be subclassed, with the subclass adding visitor methods.
Per default the visitor functions for the nodes are
'visit_'+ class name of the node. So a TryFinally node visit function would be visit_TryFinally. This behavior can be changed by overriding the visit method. If no visitor function exists for a node (return value None) the generic_visit visitor is used instead.Don’t use the NodeVisitor if you want to apply changes to nodes during traversing. For this a special visitor exists (NodeTransformer) that allows modifications.
- visit(node)
Modified from ast.NodeVisitor to match rope’s existing Visitor implementation
- rope.base.ast.get_const_subtype_name(node)
Get pre-3.8 ast node name
- rope.base.ast.get_node_type_name(node)