Remove `addnodes.document`

This commit is contained in:
Adam Turner 2025-02-11 02:22:42 +00:00
parent 47299b8229
commit b88edad731
3 changed files with 2 additions and 21 deletions

View File

@ -5,6 +5,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from docutils import nodes
from docutils.nodes import document # NoQA: F401
if TYPE_CHECKING:
from collections.abc import Sequence
@ -16,22 +17,6 @@ if TYPE_CHECKING:
from sphinx.util.typing import ExtensionMetadata
class document(nodes.document):
"""The document root element patched by Sphinx.
This fixes that document.set_id() does not support a node having multiple node Ids.
see https://sourceforge.net/p/docutils/patches/167/
.. important:: This is only for Sphinx internal use. Please don't use this
in your extensions. It will be removed without deprecation period.
"""
def set_id(
self, node: Element, msgnode: Element | None = None, suggested_prefix: str = ''
) -> str:
return super().set_id(node, msgnode, suggested_prefix)
class translatable(nodes.Node):
"""Node which supports translation.

View File

@ -10,7 +10,6 @@ from docutils.readers import standalone
from docutils.transforms.references import DanglingReferences
from docutils.writers import UnfilteredWriter
from sphinx import addnodes
from sphinx.transforms import AutoIndexUpgrader, DoctreeReadEvent, SphinxTransformer
from sphinx.transforms.i18n import (
Locale,
@ -76,7 +75,6 @@ class SphinxBaseReader(standalone.Reader): # type: ignore[misc]
for logging.
"""
document = super().new_document()
document.__class__ = addnodes.document # replace the class with patched version
# substitute transformer
document.transformer = SphinxTransformer(document)

View File

@ -813,8 +813,6 @@ def new_document(source_path: str, settings: Any = None) -> nodes.document:
settings = copy(cached_settings)
# Create a new instance of nodes.document using cached reporter
from sphinx import addnodes
document = addnodes.document(settings, reporter, source=source_path)
document = nodes.document(settings, reporter, source=source_path)
document.note_source(source_path, -1)
return document