From b56fb018f16a75822f7b4a478c0fcc1cf0ed6593 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Wed, 19 Oct 2022 10:02:55 +0100 Subject: [PATCH] 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. --- src/textual/dom.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/textual/dom.py b/src/textual/dom.py index 64770bfe7..af48bf1df 100644 --- a/src/textual/dom.py +++ b/src/textual/dom.py @@ -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.