Skip to content

Conversation

adamtheturtle
Copy link
Contributor

See code at https://github.com/docutils/docutils/blob/6d835be25d585e1dce688ef33c3876aa34ba59f0/docutils/docutils/nodes.py#L369:

    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

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
```
@adamtheturtle adamtheturtle changed the title docutils.nodes.Node.next_node can return None docutils: docutils.nodes.Node.next_node can return None Oct 5, 2025
Copy link
Contributor

github-actions bot commented Oct 5, 2025

Diff from mypy_primer, showing the effect of this PR on open source code:

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/writers/html5.py: note: In member "depart_classifier" of class "HTML5Translator":
+ sphinx/writers/html5.py:477:27: error: Incompatible types in assignment (expression has type "Node | None", variable has type "Node")  [assignment]
+ sphinx/writers/html5.py: note: In member "depart_term" of class "HTML5Translator":
+ sphinx/writers/html5.py:488:27: error: Incompatible types in assignment (expression has type "Node | None", variable has type "Node")  [assignment]
+ sphinx/writers/latex.py: note: In member "visit_target" of class "LaTeXTranslator":
+ sphinx/writers/latex.py:1855:25: error: Incompatible types in assignment (expression has type "Node | None", variable has type "Node")  [assignment]
+ sphinx/writers/texinfo.py:293: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/builders/_epub_base.py: note: In member "fix_ids" of class "EpubBuilder":
+ sphinx/builders/_epub_base.py:297:31: error: Incompatible types in assignment (expression has type "Node | None", variable has type "Node")  [assignment]

@srittau srittau merged commit 9f7ddd9 into python:main Oct 5, 2025
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants