Instead of adding the ancestors to the walk, might be worth considering adding to the AST object in one of two ways:
parent field on every node that points to its parent node (and then can be navigated to root in a linked list fashion)
ancestors field on every node that has an ordered list of ancestors (which can then be navigated by reading through the list)
Whichever one is more efficient is a design decision you're probably better equipped to make. A NodeTransformer from the ast library would be able to achieve this.
Instead of adding the ancestors to the walk, might be worth considering adding to the AST object in one of two ways:
parent
field on every node that points to its parent node (and then can be navigated to root in a linked list fashion)ancestors
field on every node that has an ordered list of ancestors (which can then be navigated by reading through the list)Whichever one is more efficient is a design decision you're probably better equipped to make. A
NodeTransformer
from theast
library would be able to achieve this._Originally posted by @somaniarushi in https://github.com/manishshettym/codescholar/pull/5#discussion_r982875161_