Skip to content
4 changes: 2 additions & 2 deletions sphinx/ext/autodoc/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

if TYPE_CHECKING:
from docutils.nodes import Node
from docutils.parsers.rst.states import RSTState

from sphinx.config import Config
from sphinx.environment import BuildEnvironment
from sphinx.util.typing import _RSTState as RSTState

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -112,7 +112,7 @@ def run(self) -> list[Node]:
reporter = self.state.document.reporter

try:
source, lineno = reporter.get_source_and_line(
source, lineno = reporter.get_source_and_line( # type: ignore[attr-defined]
self.lineno)
except AttributeError:
source, lineno = (None, None)
Expand Down
4 changes: 2 additions & 2 deletions sphinx/ext/inheritance_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ def run(self) -> list[Node]:
aliases=self.config.inheritance_alias,
top_classes=node['top-classes'])
except InheritanceException as err:
return [node.document.reporter.warning(err, line=self.lineno)] # type: ignore[union-attr]
return [node.document.reporter.warning(err, line=self.lineno)]

# Create xref nodes for each target of the graph's image map and
# add them to the doc tree so that Sphinx can resolve the
# references to real URLs later. These nodes will eventually be
# removed from the doctree after we're done with them.
for name in graph.get_all_class_names():
refnodes, x = class_role( # type: ignore[call-arg,misc]
'class', ':class:`%s`' % name, name, 0, self.state)
'class', ':class:`%s`' % name, name, 0, self.state.inliner)
node.extend(refnodes)
# Store the graph object so we can use it to generate the
# dot file later
Expand Down
3 changes: 2 additions & 1 deletion sphinx/util/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@

from docutils.nodes import Element
from docutils.parsers.rst import Directive
from docutils.parsers.rst.states import Inliner, RSTState
from docutils.parsers.rst.states import Inliner
from docutils.statemachine import StringList

from sphinx.builders import Builder
from sphinx.environment import BuildEnvironment
from sphinx.util.tags import Tags
from sphinx.util.typing import _RSTState as RSTState

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion sphinx/util/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if TYPE_CHECKING:
from collections.abc import Iterator

from docutils.parsers.rst.states import RSTState
from sphinx.util.typing import _RSTState as RSTState


def nested_parse_to_nodes(
Expand Down
2 changes: 2 additions & 0 deletions sphinx/util/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
from collections.abc import Mapping
from typing import Final, Literal

from docutils.parsers.rst.states import RSTState as _RSTStateGeneric
from typing_extensions import TypeAlias, TypeIs

from sphinx.application import Sphinx

_RSTState: TypeAlias = _RSTStateGeneric[list[str]]
_RestifyMode: TypeAlias = Literal[
'fully-qualified-except-typing',
'smart',
Expand Down
6 changes: 3 additions & 3 deletions tests/test_util/test_util_docutils_sphinx_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@


def make_directive(*, env: SimpleNamespace, input_lines: StringList | None = None) -> SphinxDirective:
state, directive = make_directive_and_state(env=env, input_lines=input_lines)
_, directive = make_directive_and_state(env=env, input_lines=input_lines)
return directive


def make_directive_and_state(*, env: SimpleNamespace, input_lines: StringList | None = None) -> tuple[RSTState, SphinxDirective]:
def make_directive_and_state(*, env: SimpleNamespace, input_lines: StringList | None = None) -> tuple[RSTState[list[str]], SphinxDirective]:
sm = RSTStateMachine(state_classes, initial_state='Body')
sm.reporter = object()
if input_lines is not None:
sm.input_lines = input_lines
state = RSTState(sm)
state: RSTState[list[str]] = RSTState(sm)
state.document = new_document('<tests>')
state.document.settings.env = env
state.document.settings.tab_width = 4
Expand Down