Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #221, avoid children attribute access on maxlevel #233

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions anytree/iterators/levelorderiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ def _iter(children, filter_, stop, maxlevel):
level = 1
while children:
next_children = []
for child in children:
if filter_(child):
yield child
next_children += AbstractIter._get_children(child.children, stop)
children = next_children
level += 1
if AbstractIter._abort_at_level(level, maxlevel):
break
for child in children:
if filter_(child):
yield child
else:
for child in children:
if filter_(child):
yield child
next_children += AbstractIter._get_children(child.children, stop)
children = next_children
13 changes: 7 additions & 6 deletions anytree/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,14 @@ def __iter__(self):

def __next(self, node, continues, level=0):
yield RenderTree.__item(node, continues, self.style)
children = node.children
level += 1
if children and (self.maxlevel is None or level < self.maxlevel):
children = self.childiter(children)
for child, is_last in _is_last(children):
for grandchild in self.__next(child, continues + (not is_last,), level=level):
yield grandchild
if self.maxlevel is None or level < self.maxlevel:
children = node.children
if children:
children = self.childiter(children)
for child, is_last in _is_last(children):
for grandchild in self.__next(child, continues + (not is_last,), level=level):
yield grandchild

@staticmethod
def __item(node, continues, style):
Expand Down