Miscellaneous improvements to the behavior and documentation of Visitor, Transformer, Interpreter, and friends
This PR makes the following improvements.
Documentation:
- Add docstrings for
visit_children_decorand various methods ofInterpreter. - Correct the top-level docs for
Visitorto clarify that it can traverse the tree in either direction. - Move utilities into their own section and add documentation for
visit_children_decor, which was previously not visible.
Behavior:
- Have
visit_children_decorraise aTypeErrorif applied to a method of any class other thanInterpreter. - Have
v_argsraise aTypeErrorif applied to aVisitoror its methods. I had to get help from GPT to figure out to make this check work. I'm not confident in the logic.
visit_topdown would actually get the Interpreter to walk the tree bottom up
Can you explain this comment? Interpreter.top_down() would just use the __default__() method, no?
Ah, I think I misinterpreted the behavior and jumped to the wrong conclusion.
Is the behavior of Interpreter.visit_topdown() fine as it is on master? Or is my proposed patch correct and just needs a fixed description?
@nchammas Well, I can see how it was confusing. But I don't think adding visit_topdown fixes anything. Interpreter is behaving as expected, and if it's not implemented with the best design, that's another matter, but adding this method won't change that.
Maybe it would be better to remove the __getattr__, but that would be slightly backwards-incompatible, in case anyone relied on this behavior, for some reason.
@erezsh - No rush; just wanted to check in again if I can do anything to move this PR forward.