class Base: (source)
Known subclasses: pytype.test_data.pytree.Leaf
, pytype.test_data.pytree.Node
Abstract base class for Node and Leaf. This provides some default functionality and boilerplate using the template pattern. A node may be a subnode of at most one parent. Each subclass of Base must provide a __str__ implementation that returns exactly the input that was used to create the item in the tree. Each subclass of Base must provide a value attribute, and the ranges of values must be distinct for each subclass. This isn't a strict requirement, but it's convenient so that instead of writing if isinstance(node, Leaf) and node.type == TOKEN.name: you can just write if node.type == TOKEN.name:
Method | __eq__ |
Compare two nodes for equality. |
Method | __ne__ |
Compare two nodes for inequality. |
Method | __new__ |
Constructor that prevents Base from being instantiated. |
Method | __str__ |
Undocumented |
Method | changed |
Undocumented |
Method | clone |
Return a cloned (deep) copy of self. |
Method | depth |
Undocumented |
Method | descend |
Takes a sequence of integers and descends via children. |
Method | get |
Return the line number which generated the invocant node. |
Method | get |
Return the prefix for the node (see Leaf class). |
Method | get |
Return the string immediately following the invocant node. This is effectively equivalent to node.next_sibling.prefix |
Method | label |
Create 'label' attritbute for each Node/Leaf. |
Method | leaves |
Undocumented |
Method | post |
Post-order iterator for the tree. |
Method | pre |
Pre-order iterator for the tree. |
Method | remove |
Remove the node from the tree. Returns the position of the node in its parent's children before it was removed. |
Method | replace |
Replace this node with a new one in the parent. |
Method | set |
Set the prefix for the node (see Leaf class). |
Class Variable | __hash__ |
Undocumented |
Class Variable | children |
Undocumented |
Class Variable | type |
Undocumented |
Class Variable | was |
Undocumented |
Instance Variable | label |
Undocumented |
Instance Variable | parent |
Undocumented |
Instance Variable | prefix |
Undocumented |
Instance Variable | was |
Undocumented |
Property | next |
The node immediately following the invocant in their parent's children list. If the invocant does not have a next sibling, it is None |
Property | prev |
The node immediately preceding the invocant in their parent's children list. If the invocant does not have a previous sibling, it is None. |
Property | type |
Get the type as a human-readable string. |
Method | _eq |
Compare two nodes for equality. |
pytype.test_data.pytree.Leaf
, pytype.test_data.pytree.Node
Return a cloned (deep) copy of self. This must be implemented by the concrete subclass.
Takes a sequence of integers and descends via children. For example, descend_to([]) returns self; descend_to([0]) returns self.children[0]; descend_to([2,5,3]) returns self.children[2].children[5],children[3]. In effect, this gives each node a unique number, which is the list of child # that is needed to get to it.
Return the string immediately following the invocant node. This is effectively equivalent to node.next_sibling.prefix
Create 'label' attritbute for each Node/Leaf. Args: indexes is used internally to keep track of the path to here.
pytype.test_data.pytree.Leaf
, pytype.test_data.pytree.Node
Post-order iterator for the tree. This must be implemented by the concrete subclass.
pytype.test_data.pytree.Leaf
, pytype.test_data.pytree.Node
Pre-order iterator for the tree. This must be implemented by the concrete subclass.
Remove the node from the tree. Returns the position of the node in its parent's children before it was removed.
The node immediately following the invocant in their parent's children list. If the invocant does not have a next sibling, it is None
The node immediately preceding the invocant in their parent's children list. If the invocant does not have a previous sibling, it is None.
pytype.test_data.pytree.Leaf
, pytype.test_data.pytree.Node
Compare two nodes for equality. This is called by __eq__ and __ne__. It is only called if the two nodes have the same type. This must be implemented by the concrete subclass. Nodes should be considered equal if they have the same structure, ignoring the prefix string and other context information.