module documentation

Base node class used to represent immutable trees. All node classes should be 'attr' classes inheriting from Node, which defines field iteration and comparison methods. For the concrete node types, see pytd/pytd.py This module also defines a visitor interface which works over immutable trees, replacing a node with a new instance if any of its fields have changed. See the documentation in the various visitor methods below for details. For examples of visitors, see pytd/visitors.py

Class Node Base Node class.
Function _Visit Visit the node.
Function _VisitNode Transform a node and all its children using a visitor.
Variable _visiting Undocumented
def _Visit(node, visitor, *args, **kwargs): (source)

Visit the node.

def _VisitNode(node, visitor, *args, **kwargs): (source)

Transform a node and all its children using a visitor. This will iterate over all children of this node, and also process certain things that are not nodes. The latter are either tuples, which will have their elements visited, or primitive types, which will be returned as-is. Args: node: The node to transform. Either an actual instance of Node, or a tuple found while scanning a node tree, or any other type (which will be returned unmodified). visitor: The visitor to apply. If this visitor has a "Visit<Name>" method, with <Name> the name of the Node class, a callback will be triggered, and the transformed version of this node will be whatever the callback returned. Before calling the Visit callback, the following attribute(s) on the Visitor class will be populated: visitor.old_node: The node before the child nodes were visited. Additionally, if the visitor has a "Enter<Name>" method, that method will be called on the original node before descending into it. If "Enter<Name>" returns False, the visitor will not visit children of this node. If "Enter<name>" returns a set of field names, those field names will not be visited. Otherwise, "Enter<Name>" should return None, to indicate that nodes will be visited normally. "Enter<Name>" is called pre-order; "Visit<Name> and "Leave<Name>" are called post-order. A counterpart to "Enter<Name>" is "Leave<Name>", which is intended for any clean-up that "Enter<Name>" needs (other than that, it's redundant, and could be combined with "Visit<Name>"). *args: Passed to visitor callbacks. **kwargs: Passed to visitor callbacks. Returns: The transformed Node (which *may* be the original node but could be a new node, even if the contents are the same).

_visiting = (source)

Undocumented