diff --git a/pyproject.toml b/pyproject.toml index 944c8c8b0..5d4b7cdce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -136,26 +136,19 @@ exclude = [ [tool.mypy] files = ["sphinx", "utils", "tests"] exclude = [ - "tests/certs", - "tests/js", "tests/roots", # tests/ "^tests/test_events\\.py$", "^tests/test_quickstart\\.py$", "^tests/test_search\\.py$", - "^tests/test_versioning\\.py$", # tests/test_builders - "^tests/test_builders/test_build_dirhtml\\.py$", "^tests/test_builders/test_build_epub\\.py$", - "^tests/test_builders/test_builder\\.py$", "^tests/test_builders/test_build_gettext\\.py$", - "^tests/test_builders/test_build_html\\.py$", "^tests/test_builders/test_build_latex\\.py$", "^tests/test_builders/test_build_texinfo\\.py$", # tests/test_config "^tests/test_config/test_config\\.py$", # tests/test_directives - "^tests/test_directives/test_directive_object_description\\.py$", "^tests/test_directives/test_directive_only\\.py$", "^tests/test_directives/test_directive_other\\.py$", "^tests/test_directives/test_directive_patch\\.py$", @@ -185,14 +178,10 @@ exclude = [ "^tests/test_extensions/test_ext_napoleon_docstring\\.py$", # tests/test_intl "^tests/test_intl/test_intl\\.py$", - # tests/test_markup - "^tests/test_markup/test_markup\\.py$", # tests/test_pycode "^tests/test_pycode/test_pycode\\.py$", "^tests/test_pycode/test_pycode_ast\\.py$", - # tests/test_theming # tests/test_transforms - "^tests/test_transforms/test_transforms_move_module_targets\\.py$", "^tests/test_transforms/test_transforms_post_transforms\\.py$", # tests/test_util "^tests/test_util/test_util_fileutil\\.py$", diff --git a/tests/test_builders/test_build_dirhtml.py b/tests/test_builders/test_build_dirhtml.py index 3db215262..e80d2a384 100644 --- a/tests/test_builders/test_build_dirhtml.py +++ b/tests/test_builders/test_build_dirhtml.py @@ -27,14 +27,14 @@ def test_dirhtml(app): with (app.outdir / 'objects.inv').open('rb') as f: invdata = InventoryFile.load(f, 'path/to', posixpath.join) - assert 'index' in invdata.get('std:doc') + assert 'index' in invdata.get('std:doc', {}) assert invdata['std:doc']['index'] == ('Project name not set', '', 'path/to/', '-') - assert 'foo/index' in invdata.get('std:doc') + assert 'foo/index' in invdata.get('std:doc', {}) assert invdata['std:doc']['foo/index'] == ('Project name not set', '', 'path/to/foo/', '-') - assert 'index' in invdata.get('std:label') + assert 'index' in invdata.get('std:label', {}) assert invdata['std:label']['index'] == ('Project name not set', '', 'path/to/#index', '-') - assert 'foo' in invdata.get('std:label') + assert 'foo' in invdata.get('std:label', {}) assert invdata['std:label']['foo'] == ('Project name not set', '', 'path/to/foo/#foo', 'foo/index') diff --git a/tests/test_builders/test_build_epub.py b/tests/test_builders/test_build_epub.py index 6aadaa139..c0f653c2b 100644 --- a/tests/test_builders/test_build_epub.py +++ b/tests/test_builders/test_build_epub.py @@ -174,7 +174,7 @@ def test_nested_toc(app): assert toc.find("./ncx:docTitle/ncx:text").text == 'Project name not set' # toc.ncx / navPoint - def navinfo(elem): + def navinfo(elem: EPUBElementTree): label = elem.find("./ncx:navLabel/ncx:text") content = elem.find("./ncx:content") return (elem.get('id'), elem.get('playOrder'), diff --git a/tests/test_builders/test_build_html.py b/tests/test_builders/test_build_html.py index 2a489e47b..28745ae9f 100644 --- a/tests/test_builders/test_build_html.py +++ b/tests/test_builders/test_build_html.py @@ -1,8 +1,11 @@ """Test the HTML builder and check output against XPath.""" +from __future__ import annotations + import os import posixpath import re +from typing import TYPE_CHECKING import pytest @@ -14,6 +17,9 @@ from sphinx.util.inventory import InventoryFile from tests.test_builders.xpath_data import FIGURE_CAPTION from tests.test_builders.xpath_util import check_xpath +if TYPE_CHECKING: + from typing import Any + def test_html_sidebars_error(make_app, tmp_path): (tmp_path / 'conf.py').touch() @@ -230,7 +236,7 @@ def test_html_style(app): @pytest.mark.sphinx('html', testroot='basic') def test_html_sidebar(app): - ctx = {} + ctx: dict[str, Any] = {} # default for alabaster app.build(force_all=True) @@ -398,7 +404,7 @@ def test_html_pep_695_one_type_per_line(app, cached_etree_parse): etree = cached_etree_parse(fname) class chk: - def __init__(self, expect): + def __init__(self, expect: str) -> None: self.expect = expect def __call__(self, nodes): diff --git a/tests/test_directives/test_directive_object_description.py b/tests/test_directives/test_directive_object_description.py index 4b5107ebf..8808c3580 100644 --- a/tests/test_directives/test_directive_object_description.py +++ b/tests/test_directives/test_directive_object_description.py @@ -1,5 +1,9 @@ """Test object description directives.""" +from __future__ import annotations + +from typing import TYPE_CHECKING + import docutils.utils import pytest from docutils import nodes @@ -9,8 +13,11 @@ from sphinx.io import create_publisher from sphinx.testing import restructuredtext from sphinx.util.docutils import sphinx_domains +if TYPE_CHECKING: + from sphinx.builders import Builder -def _doctree_for_test(builder, docname: str) -> nodes.document: + +def _doctree_for_test(builder: Builder, docname: str) -> nodes.document: builder.env.prepare_settings(docname) publisher = create_publisher(builder.app, 'restructuredtext') with sphinx_domains(builder.env): diff --git a/tests/test_markup/test_markup.py b/tests/test_markup/test_markup.py index e92f75e26..cad357b0e 100644 --- a/tests/test_markup/test_markup.py +++ b/tests/test_markup/test_markup.py @@ -17,7 +17,8 @@ from sphinx.testing.util import assert_node from sphinx.transforms import SphinxSmartQuotes from sphinx.util import texescape from sphinx.util.docutils import sphinx_domains -from sphinx.writers.html import HTML5Translator, HTMLWriter +from sphinx.writers.html import HTMLWriter +from sphinx.writers.html5 import HTML5Translator from sphinx.writers.latex import LaTeXTranslator, LaTeXWriter @@ -65,7 +66,7 @@ def parse(new_document): document = new_document() parser = RstParser() parser.parse(rst, document) - SphinxSmartQuotes(document, startnode=None).apply() + SphinxSmartQuotes(document, startnode=None).apply() # type: ignore[no-untyped-call] for msg in list(document.findall(nodes.system_message)): if msg['level'] == 1: msg.replace_self([]) diff --git a/tests/test_transforms/test_transforms_move_module_targets.py b/tests/test_transforms/test_transforms_move_module_targets.py index e0e9f1de5..6483a00fa 100644 --- a/tests/test_transforms/test_transforms_move_module_targets.py +++ b/tests/test_transforms/test_transforms_move_module_targets.py @@ -32,7 +32,7 @@ def test_move_module_targets(tmp_path, content): app = SphinxTestApp('dummy', srcdir=tmp_path) app.build(force_all=True) document = app.env.get_doctree('index') - section = document[0] + section: nodes.section = document[0] # type: ignore[assignment] # target ID has been lifted into the section node assert section["ids"] == ['module-fish_licence.halibut', 'move-module-targets'] @@ -65,11 +65,11 @@ def test_move_module_targets_disabled(tmp_path): app.registry.transforms.remove(MoveModuleTargets) # disable the transform app.build(force_all=True) document = app.env.get_doctree('index') - section = document[0] + section: nodes.section = document[0] # type: ignore[assignment] # target ID is not lifted into the section node assert section["ids"] == ['move-module-targets'] - assert section[2]["ids"] == ['module-fish_licence.halibut'] + assert section[2]["ids"] == ['module-fish_licence.halibut'] # type: ignore[index] # nodes.target remains in 'section' assert isinstance(section[0], nodes.title) assert isinstance(section[1], addnodes.index) diff --git a/tests/test_versioning.py b/tests/test_versioning.py index ae159dfeb..f74b420fe 100644 --- a/tests/test_versioning.py +++ b/tests/test_versioning.py @@ -22,7 +22,7 @@ def _setup_module(rootdir, sphinx_test_tempdir): app.connect('doctree-resolved', on_doctree_resolved) app.build() original = doctrees['original'] - original_uids = [n.uid for n in add_uids(original, is_paragraph)] + original_uids = [n.uid for n in add_uids(original, is_paragraph)] # type: ignore[attr-defined] yield app.cleanup() @@ -115,6 +115,6 @@ def test_insert_similar(): new_nodes = list(merge_doctrees(original, insert_similar, is_paragraph)) uids = [n.uid for n in insert_similar.findall(is_paragraph)] assert len(new_nodes) == 1 - assert new_nodes[0].rawsource == 'Anyway I need more' + assert new_nodes[0].rawsource == 'Anyway I need more' # type: ignore[attr-defined] assert original_uids[0] == uids[0] assert original_uids[1:] == uids[2:]