I have two classes AST and ASTNode for working with some tree-like data. Both these classes have networkx graph as a field and a node id (integer). For AST this id refers to the root of a tree. These two classes looks pretty similar, but I have splited functionality in a following way:
- I use
ASTfor global functionality like get nodes of some type from a whole tree - I use
ASTNodefor local functionality like get direct child of a node and other node properties
I need to be able to shift from AST to ASTNode functionality and backward when needed. Here comes circular dependency. I want to be able:
- to query some
ASTNodefromAST - to build a subtree from
ASTNodewith this node as a root
So this makes ASTNode to know how to create AST. How can I deal with it? Should I use absolute module import? Or it can be done otherwise?
Currently I moved get_subtree(node) function to AST, but this make usage really uncomfortable (you have to pass node and a tree together all the time).