Modify DOMNode.walk_children to return a list

Originally it returned an iterable, building that up from a list anyway. In
local discussion it's been decided that it makes more sense to simply return
the list. There's no obvious advantage to doing it a different way.
This commit is contained in:
Dave Pearson
2022-10-19 10:02:55 +01:00
parent 4b3b622b35
commit b56fb018f1

View File

@@ -634,7 +634,7 @@ class DOMNode(MessagePump):
with_self: bool = True,
method: WalkMethod = "depth",
reverse: bool = False,
) -> Iterable[WalkType]:
) -> list[WalkType]:
...
@overload
@@ -644,7 +644,7 @@ class DOMNode(MessagePump):
with_self: bool = True,
method: WalkMethod = "depth",
reverse: bool = False,
) -> Iterable[DOMNode]:
) -> list[DOMNode]:
...
def walk_children(
@@ -654,7 +654,7 @@ class DOMNode(MessagePump):
with_self: bool = True,
method: WalkMethod = "depth",
reverse: bool = False,
) -> Iterable[DOMNode | WalkType]:
) -> list[DOMNode] | list[WalkType]:
"""Generate descendant nodes.
Args:
@@ -665,7 +665,7 @@ class DOMNode(MessagePump):
reverse (bool, optional): Reverse the order (bottom up). Defaults to False.
Returns:
Iterable[DOMNode | WalkType]: An iterable of nodes.
list[DOMNode] | list[WalkType]: A list of nodes.
"""
@@ -712,9 +712,8 @@ class DOMNode(MessagePump):
# change mid-walk
nodes = list(node_generator)
if reverse:
yield from reversed(nodes)
else:
yield from nodes
nodes.reverse()
return nodes
def get_child(self, id: str) -> DOMNode:
"""Return the first child (immediate descendent) of this node with the given ID.