Update MyPy for types-docutils 0.21.0.20240704 (#12511)

Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
James Addison 2024-07-06 19:29:18 +01:00 committed by GitHub
parent b23ac4f16e
commit e63e2f3ccb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 12 additions and 9 deletions

View File

@ -13,10 +13,10 @@ from sphinx.util.parsing import nested_parse_to_nodes
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__)
@ -112,7 +112,7 @@ class AutodocDirective(SphinxDirective):
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)

View File

@ -378,7 +378,7 @@ class InheritanceDiagram(SphinxDirective):
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
@ -386,7 +386,7 @@ class InheritanceDiagram(SphinxDirective):
# 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

View File

@ -20,12 +20,13 @@ if TYPE_CHECKING:
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__)

View File

@ -11,7 +11,7 @@ from docutils.statemachine import StringList, string2lines
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(

View File

@ -26,10 +26,12 @@ if TYPE_CHECKING:
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',

View File

@ -11,16 +11,16 @@ from sphinx.util.docutils import SphinxDirective, new_document
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