I have a Python AST that I'd like to traverse breadth first. ast.walk
appears to do the trick, but from its documentation
ast.walk(node)
Recursively yield all descendant nodes in the tree starting at
node
(includingnode
itself), in no specified order. This is useful if you only want to modify nodes in place and don’t care about the context.
one might assume that this is merely an implementation detail. Is there a traversal method that guaranteed breadth-first?