def _get_matching_child(
parent_node: nodes.Element, child_class: nodes.Element, last=True):
"""Get the first or last child node that matches a Node subclass.
Args:
parent_node: The node to find the child of.
child_class: The Node subclass to check against.
last: If True, find the last matching child. If False, find the first
one.
Returns:
The first or last child Node object that is an instance of the given
class.
"""
if last:
children = reversed(parent_node.children)
else:
children = parent_node.children
for child_node in children:
if isinstance(child_node, child_class):
return child_node
评论列表
文章目录