class documentation
class Ancestors(gast.NodeVisitor): (source)
Build the ancestor tree, that associates a node to the list of node visited from the root node (the Module) to the current node.
Example usage with gast module >>> from beniget import Ancestors >>> code = 'def foo(x): return x + 1'
>>> import gast >>> module = gast.parse(code)
>>> ancestors = Ancestors() >>> ancestors.visit(module)
>>> binop = module.body[0].body[0].value >>> for n in ancestors.parents(binop): ... print(type(n)) <class 'gast.gast.Module'> <class 'gast.gast.FunctionDef'> <class 'gast.gast.Return'>
>>> import ast >>> code = 'def foo(x): return x + 1' >>> module = ast.parse(code)
>>> ancestors = Ancestors() >>> ancestors.visit(module)
>>> binop = module.body[0].body[0].value >>> for n in ancestors.parents(binop): ... print(type(n).__name__) Module FunctionDef Return
| Method | __init__ |
Undocumented |
| Method | generic |
Undocumented |
| Method | parent |
Undocumented |
| Method | parent |
Undocumented |
| Method | parent |
Undocumented |
| Method | parents |
Undocumented |
| Method | parent |
Undocumented |
| Instance Variable | _current |
Undocumented |
| Instance Variable | _parents |
Undocumented |