From 6a10e6547346547d8073a410f9ae382a774db2a3 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Wed, 31 Jul 2024 12:24:56 +0100 Subject: [PATCH] Harmonise ``Builder.write_doc()`` --- sphinx/builders/dummy.py | 4 ++-- sphinx/builders/text.py | 4 ++-- sphinx/builders/xml.py | 6 ++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/sphinx/builders/dummy.py b/sphinx/builders/dummy.py index 9c7ce834e23..05b7e568791 100644 --- a/sphinx/builders/dummy.py +++ b/sphinx/builders/dummy.py @@ -8,7 +8,7 @@ from sphinx.locale import __ if TYPE_CHECKING: - from docutils.nodes import Node + from docutils import nodes from sphinx.application import Sphinx from sphinx.util.typing import ExtensionMetadata @@ -32,7 +32,7 @@ def get_target_uri(self, docname: str, typ: str | None = None) -> str: def prepare_writing(self, docnames: set[str]) -> None: pass - def write_doc(self, docname: str, doctree: Node) -> None: + def write_doc(self, docname: str, doctree: nodes.document) -> None: pass def finish(self) -> None: diff --git a/sphinx/builders/text.py b/sphinx/builders/text.py index ec0eecfb561..92544034c49 100644 --- a/sphinx/builders/text.py +++ b/sphinx/builders/text.py @@ -20,7 +20,7 @@ if TYPE_CHECKING: from collections.abc import Iterator - from docutils.nodes import Node + from docutils import nodes from sphinx.application import Sphinx from sphinx.util.typing import ExtensionMetadata @@ -67,7 +67,7 @@ def get_target_uri(self, docname: str, typ: str | None = None) -> str: def prepare_writing(self, docnames: set[str]) -> None: self.writer = TextWriter(self) - def write_doc(self, docname: str, doctree: Node) -> None: + def write_doc(self, docname: str, doctree: nodes.document) -> None: self.current_docname = docname self.secnumbers = self.env.toc_secnumbers.get(docname, {}) destination = StringOutput(encoding='utf-8') diff --git a/sphinx/builders/xml.py b/sphinx/builders/xml.py index 947c7d2798d..6be0ff8d6e4 100644 --- a/sphinx/builders/xml.py +++ b/sphinx/builders/xml.py @@ -22,8 +22,6 @@ if TYPE_CHECKING: from collections.abc import Iterator - from docutils.nodes import Node - from sphinx.application import Sphinx from sphinx.util.typing import ExtensionMetadata @@ -73,13 +71,13 @@ def get_target_uri(self, docname: str, typ: str | None = None) -> str: def prepare_writing(self, docnames: set[str]) -> None: self.writer = self._writer_class(self) - def write_doc(self, docname: str, doctree: Node) -> None: + def write_doc(self, docname: str, doctree: nodes.document) -> None: # work around multiple string % tuple issues in docutils; # replace tuples in attribute values with lists doctree = doctree.deepcopy() for domain in self.env.domains.values(): xmlns = "xmlns:" + domain.name - doctree[xmlns] = "https://www.sphinx-doc.org/" # type: ignore[index] + doctree[xmlns] = "https://www.sphinx-doc.org/" for node in doctree.findall(nodes.Element): for att, value in node.attributes.items(): if isinstance(value, tuple):