Recursively iterating through a template's nodes
|Reported by:||miracle2k||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||no|
Right now, for node in Template() will only yield the top-level nodes. Is this the way it is intended to work? I was expecting to get all nodes, recursively.
The Template.__iter__ code looks like this:
def __iter__(self): for node in self.nodelist: for subnode in node: yield subnode
And Node.__iter__ does:
def __iter__(self): yield self
This looks like a precipe to allow nodes to yield their childnodes, without relying on the existence of the nodelist attribute.
However, nodes like BlockNode and ExtendsNode do not implement __iter__ - only ForNode and IfNode seem to do, and not in the way I would have expected (they don't yield self).
Is this a bug, or per design?
Change History (7)
comment:1 Changed 8 years ago by
|Patch needs improvement:||unset|