File tree 1 file changed +10
-2
lines changed
w3/python/core/fundamental_interface 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -188,7 +188,7 @@ def first_child(self) -> Optional[_AnyNode]:
188
188
189
189
If there is no such node, this returns `None`.
190
190
"""
191
- if not self .child_nodes :
191
+ if not self .has_child_nodes () :
192
192
return None
193
193
return self .child_nodes .item (0 )
194
194
@@ -198,7 +198,7 @@ def last_child(self) -> Optional[_AnyNode]:
198
198
199
199
If there is no such node, this returns `None`.
200
200
"""
201
- if not self .child_nodes :
201
+ if not self .has_child_nodes () :
202
202
return None
203
203
return self .child_nodes .item (self .child_nodes .length - 1 )
204
204
@@ -266,6 +266,14 @@ def _set_owner_document(self,
266
266
"""Indirect accessor to set the 'owner_document' property."""
267
267
self ._owner_document = owner_document
268
268
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
+
269
277
270
278
_AnyNode = Node
271
279
_NamedNodeMap = Dict [str , _AnyNode ] # TODO: Implement NamedNodeMap (#19)
You can’t perform that action at this time.
0 commit comments