Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f09bc62

Browse files
Shrink mypy exclude list (sphinx-doc#12669)
Co-authored-by: Adam Turner <[email protected]>
1 parent 68eaf08 commit f09bc62

8 files changed

Lines changed: 29 additions & 26 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,26 +136,19 @@ exclude = [
136136
[tool.mypy]
137137
files = ["sphinx", "utils", "tests"]
138138
exclude = [
139-
"tests/certs",
140-
"tests/js",
141139
"tests/roots",
142140
# tests/
143141
"^tests/test_events\\.py$",
144142
"^tests/test_quickstart\\.py$",
145143
"^tests/test_search\\.py$",
146-
"^tests/test_versioning\\.py$",
147144
# tests/test_builders
148-
"^tests/test_builders/test_build_dirhtml\\.py$",
149145
"^tests/test_builders/test_build_epub\\.py$",
150-
"^tests/test_builders/test_builder\\.py$",
151146
"^tests/test_builders/test_build_gettext\\.py$",
152-
"^tests/test_builders/test_build_html\\.py$",
153147
"^tests/test_builders/test_build_latex\\.py$",
154148
"^tests/test_builders/test_build_texinfo\\.py$",
155149
# tests/test_config
156150
"^tests/test_config/test_config\\.py$",
157151
# tests/test_directives
158-
"^tests/test_directives/test_directive_object_description\\.py$",
159152
"^tests/test_directives/test_directive_only\\.py$",
160153
"^tests/test_directives/test_directive_other\\.py$",
161154
"^tests/test_directives/test_directive_patch\\.py$",
@@ -185,14 +178,10 @@ exclude = [
185178
"^tests/test_extensions/test_ext_napoleon_docstring\\.py$",
186179
# tests/test_intl
187180
"^tests/test_intl/test_intl\\.py$",
188-
# tests/test_markup
189-
"^tests/test_markup/test_markup\\.py$",
190181
# tests/test_pycode
191182
"^tests/test_pycode/test_pycode\\.py$",
192183
"^tests/test_pycode/test_pycode_ast\\.py$",
193-
# tests/test_theming
194184
# tests/test_transforms
195-
"^tests/test_transforms/test_transforms_move_module_targets\\.py$",
196185
"^tests/test_transforms/test_transforms_post_transforms\\.py$",
197186
# tests/test_util
198187
"^tests/test_util/test_util_fileutil\\.py$",

tests/test_builders/test_build_dirhtml.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ def test_dirhtml(app):
2727
with (app.outdir / 'objects.inv').open('rb') as f:
2828
invdata = InventoryFile.load(f, 'path/to', posixpath.join)
2929

30-
assert 'index' in invdata.get('std:doc')
30+
assert 'index' in invdata.get('std:doc', {})
3131
assert invdata['std:doc']['index'] == ('Project name not set', '', 'path/to/', '-')
3232

33-
assert 'foo/index' in invdata.get('std:doc')
33+
assert 'foo/index' in invdata.get('std:doc', {})
3434
assert invdata['std:doc']['foo/index'] == ('Project name not set', '', 'path/to/foo/', '-')
3535

36-
assert 'index' in invdata.get('std:label')
36+
assert 'index' in invdata.get('std:label', {})
3737
assert invdata['std:label']['index'] == ('Project name not set', '', 'path/to/#index', '-')
3838

39-
assert 'foo' in invdata.get('std:label')
39+
assert 'foo' in invdata.get('std:label', {})
4040
assert invdata['std:label']['foo'] == ('Project name not set', '', 'path/to/foo/#foo', 'foo/index')

tests/test_builders/test_build_epub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def test_nested_toc(app):
174174
assert toc.find("./ncx:docTitle/ncx:text").text == 'Project name not set'
175175

176176
# toc.ncx / navPoint
177-
def navinfo(elem):
177+
def navinfo(elem: EPUBElementTree):
178178
label = elem.find("./ncx:navLabel/ncx:text")
179179
content = elem.find("./ncx:content")
180180
return (elem.get('id'), elem.get('playOrder'),

tests/test_builders/test_build_html.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""Test the HTML builder and check output against XPath."""
22

3+
from __future__ import annotations
4+
35
import os
46
import posixpath
57
import re
8+
from typing import TYPE_CHECKING
69

710
import pytest
811

@@ -14,6 +17,9 @@
1417
from tests.test_builders.xpath_data import FIGURE_CAPTION
1518
from tests.test_builders.xpath_util import check_xpath
1619

20+
if TYPE_CHECKING:
21+
from typing import Any
22+
1723

1824
def test_html_sidebars_error(make_app, tmp_path):
1925
(tmp_path / 'conf.py').touch()
@@ -230,7 +236,7 @@ def test_html_style(app):
230236

231237
@pytest.mark.sphinx('html', testroot='basic')
232238
def test_html_sidebar(app):
233-
ctx = {}
239+
ctx: dict[str, Any] = {}
234240

235241
# default for alabaster
236242
app.build(force_all=True)
@@ -398,7 +404,7 @@ def test_html_pep_695_one_type_per_line(app, cached_etree_parse):
398404
etree = cached_etree_parse(fname)
399405

400406
class chk:
401-
def __init__(self, expect):
407+
def __init__(self, expect: str) -> None:
402408
self.expect = expect
403409

404410
def __call__(self, nodes):

tests/test_directives/test_directive_object_description.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""Test object description directives."""
22

3+
from __future__ import annotations
4+
5+
from typing import TYPE_CHECKING
6+
37
import docutils.utils
48
import pytest
59
from docutils import nodes
@@ -9,8 +13,11 @@
913
from sphinx.testing import restructuredtext
1014
from sphinx.util.docutils import sphinx_domains
1115

16+
if TYPE_CHECKING:
17+
from sphinx.builders import Builder
18+
1219

13-
def _doctree_for_test(builder, docname: str) -> nodes.document:
20+
def _doctree_for_test(builder: Builder, docname: str) -> nodes.document:
1421
builder.env.prepare_settings(docname)
1522
publisher = create_publisher(builder.app, 'restructuredtext')
1623
with sphinx_domains(builder.env):

tests/test_markup/test_markup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from sphinx.transforms import SphinxSmartQuotes
1818
from sphinx.util import texescape
1919
from sphinx.util.docutils import sphinx_domains
20-
from sphinx.writers.html import HTML5Translator, HTMLWriter
20+
from sphinx.writers.html import HTMLWriter
21+
from sphinx.writers.html5 import HTML5Translator
2122
from sphinx.writers.latex import LaTeXTranslator, LaTeXWriter
2223

2324

@@ -65,7 +66,7 @@ def parse_(rst):
6566
document = new_document()
6667
parser = RstParser()
6768
parser.parse(rst, document)
68-
SphinxSmartQuotes(document, startnode=None).apply()
69+
SphinxSmartQuotes(document, startnode=None).apply() # type: ignore[no-untyped-call]
6970
for msg in list(document.findall(nodes.system_message)):
7071
if msg['level'] == 1:
7172
msg.replace_self([])

tests/test_transforms/test_transforms_move_module_targets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_move_module_targets(tmp_path, content):
3232
app = SphinxTestApp('dummy', srcdir=tmp_path)
3333
app.build(force_all=True)
3434
document = app.env.get_doctree('index')
35-
section = document[0]
35+
section: nodes.section = document[0] # type: ignore[assignment]
3636

3737
# target ID has been lifted into the section node
3838
assert section["ids"] == ['module-fish_licence.halibut', 'move-module-targets']
@@ -65,11 +65,11 @@ def test_move_module_targets_disabled(tmp_path):
6565
app.registry.transforms.remove(MoveModuleTargets) # disable the transform
6666
app.build(force_all=True)
6767
document = app.env.get_doctree('index')
68-
section = document[0]
68+
section: nodes.section = document[0] # type: ignore[assignment]
6969

7070
# target ID is not lifted into the section node
7171
assert section["ids"] == ['move-module-targets']
72-
assert section[2]["ids"] == ['module-fish_licence.halibut']
72+
assert section[2]["ids"] == ['module-fish_licence.halibut'] # type: ignore[index]
7373
# nodes.target remains in 'section'
7474
assert isinstance(section[0], nodes.title)
7575
assert isinstance(section[1], addnodes.index)

tests/test_versioning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _setup_module(rootdir, sphinx_test_tempdir):
2222
app.connect('doctree-resolved', on_doctree_resolved)
2323
app.build()
2424
original = doctrees['original']
25-
original_uids = [n.uid for n in add_uids(original, is_paragraph)]
25+
original_uids = [n.uid for n in add_uids(original, is_paragraph)] # type: ignore[attr-defined]
2626
yield
2727
app.cleanup()
2828

@@ -115,6 +115,6 @@ def test_insert_similar():
115115
new_nodes = list(merge_doctrees(original, insert_similar, is_paragraph))
116116
uids = [n.uid for n in insert_similar.findall(is_paragraph)]
117117
assert len(new_nodes) == 1
118-
assert new_nodes[0].rawsource == 'Anyway I need more'
118+
assert new_nodes[0].rawsource == 'Anyway I need more' # type: ignore[attr-defined]
119119
assert original_uids[0] == uids[0]
120120
assert original_uids[1:] == uids[2:]

0 commit comments

Comments
 (0)