From b5ebe5d462626a4fb79b8a7273502e7786f7ab97 Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Sun, 5 Oct 2025 09:08:52 +0100 Subject: [PATCH] docutils.nodes.Node.next_node can return `None` See code at https://github.com/docutils/docutils/blob/6d835be25d585e1dce688ef33c3876aa34ba59f0/docutils/docutils/nodes.py#L369: ```python def next_node(self, condition: type | Callable[[Node], bool] | None = None, include_self: bool = False, descend: bool = True, siblings: bool = False, ascend: bool = False, ) -> Node | None: """ Return the first node in the iterator returned by findall(), or None if the iterable is empty. Parameter list is the same as of `findall()`. Note that `include_self` defaults to False, though. """ try: return next(self.findall(condition, include_self, descend, siblings, ascend)) except StopIteration: return None ``` --- stubs/docutils/docutils/nodes.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/docutils/docutils/nodes.pyi b/stubs/docutils/docutils/nodes.pyi index 9453b537e163..82a5fba393a1 100644 --- a/stubs/docutils/docutils/nodes.pyi +++ b/stubs/docutils/docutils/nodes.pyi @@ -89,7 +89,7 @@ class Node: @overload def next_node( self, condition: type[_N], include_self: bool = False, descend: bool = True, siblings: bool = False, ascend: bool = False - ) -> _N: ... + ) -> _N | None: ... @overload def next_node( self, @@ -98,7 +98,7 @@ class Node: descend: bool = True, siblings: bool = False, ascend: bool = False, - ) -> Node: ... + ) -> Node | None: ... def validate(self, recursive: bool = True) -> None: ... def validate_position(self) -> None: ...