File tree Expand file tree Collapse file tree 1 file changed +20
-12
lines changed Expand file tree Collapse file tree 1 file changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -56,23 +56,31 @@ def walk_depth_first(
5656 Returns:
5757 An iterable of DOMNodes, or the type specified in ``filter_type``.
5858 """
59- from textual .dom import DOMNode
60-
6159 stack : list [Iterator [DOMNode ]] = [iter (root .children )]
6260 pop = stack .pop
6361 push = stack .append
64- check_type = filter_type or DOMNode
6562
66- if with_root and isinstance ( root , check_type ) :
67- yield root
68- while stack :
69- if ( node := next ( stack [ - 1 ], None )) is None :
70- pop ()
71- else :
72- if isinstance ( node , check_type ) :
63+ if filter_type is None :
64+ if with_root :
65+ yield root
66+ while stack :
67+ if ( node := next ( stack [ - 1 ], None )) is None :
68+ pop ()
69+ else :
7370 yield node
74- if children := node ._nodes :
75- push (iter (children ))
71+ if children := node ._nodes :
72+ push (iter (children ))
73+ else :
74+ if with_root and isinstance (root , filter_type ):
75+ yield root
76+ while stack :
77+ if (node := next (stack [- 1 ], None )) is None :
78+ pop ()
79+ else :
80+ if isinstance (node , filter_type ):
81+ yield node
82+ if children := node ._nodes :
83+ push (iter (children ))
7684
7785
7886if TYPE_CHECKING :
You can’t perform that action at this time.
0 commit comments