Commit 9d60179a authored by Stefan Behnel's avatar Stefan Behnel

Add a `visitchild()` helper method to VisitorTransform that correctly...

Add a `visitchild()` helper method to VisitorTransform that correctly reassigns the result, which is easily forgotten.
parent 958df064
......@@ -19,6 +19,7 @@ cdef class VisitorTransform(TreeVisitor):
cpdef visitchildren(self, parent, attrs=*, exclude=*)
cdef list _flatten_list(self, list orig_list)
cdef list _select_attrs(self, attrs, exclude)
cpdef visitchild(self, parent, str attr, idx=*)
cdef class CythonTransform(VisitorTransform):
cdef public context
......
......@@ -276,6 +276,15 @@ class VisitorTransform(TreeVisitor):
newlist.append(x)
return newlist
def visitchild(self, parent, attr, idx=0):
# Helper to visit specific children from Python subclasses
child = getattr(parent, attr)
if attr is not None:
node = self._visitchild(child, parent, attr, idx)
if node is not child:
setattr(parent, attr, node)
return child
def recurse_to_children(self, node):
self._process_children(node)
return node
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment