Skip to content

Commit 122b77e

Browse files
committed
Create method has_child_nodes() (#16)
1 parent b590a07 commit 122b77e

File tree

1 file changed

+10
-2
lines changed
  • w3/python/core/fundamental_interface

1 file changed

+10
-2
lines changed

w3/python/core/fundamental_interface/Node.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def first_child(self) -> Optional[_AnyNode]:
188188
189189
If there is no such node, this returns `None`.
190190
"""
191-
if not self.child_nodes:
191+
if not self.has_child_nodes():
192192
return None
193193
return self.child_nodes.item(0)
194194

@@ -198,7 +198,7 @@ def last_child(self) -> Optional[_AnyNode]:
198198
199199
If there is no such node, this returns `None`.
200200
"""
201-
if not self.child_nodes:
201+
if not self.has_child_nodes():
202202
return None
203203
return self.child_nodes.item(self.child_nodes.length-1)
204204

@@ -266,6 +266,14 @@ def _set_owner_document(self,
266266
"""Indirect accessor to set the 'owner_document' property."""
267267
self._owner_document = owner_document
268268

269+
def has_child_nodes(self) -> bool:
270+
"""This is a convenience method to allow easy determination of whether a node has any children.
271+
272+
Returns:
273+
`True` if the node has any children, `False` if the node has no children.
274+
"""
275+
return bool(self.child_nodes)
276+
269277

270278
_AnyNode = Node
271279
_NamedNodeMap = Dict[str, _AnyNode] # TODO: Implement NamedNodeMap (#19)

0 commit comments

Comments
 (0)