Skip to content

Commit 7406d42

Browse files
authored
Move mypy test module exclusions to per-module ignores (#13265)
1 parent bde37be commit 7406d42

13 files changed

+113
-94
lines changed

pyproject.toml

Lines changed: 68 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -146,59 +146,6 @@ files = [
146146
]
147147
exclude = [
148148
"tests/roots",
149-
# tests/
150-
"^tests/test_quickstart\\.py$",
151-
"^tests/test_search\\.py$",
152-
# tests/test_builders
153-
"^tests/test_builders/test_build_epub\\.py$",
154-
"^tests/test_builders/test_build_gettext\\.py$",
155-
"^tests/test_builders/test_build_latex\\.py$",
156-
"^tests/test_builders/test_build_texinfo\\.py$",
157-
# tests/test_config
158-
"^tests/test_config/test_config\\.py$",
159-
# tests/test_directives
160-
"^tests/test_directives/test_directive_only\\.py$",
161-
"^tests/test_directives/test_directive_other\\.py$",
162-
"^tests/test_directives/test_directive_patch\\.py$",
163-
# tests/test_domains
164-
"^tests/test_domains/test_domain_c\\.py$",
165-
"^tests/test_domains/test_domain_cpp\\.py$",
166-
"^tests/test_domains/test_domain_js\\.py$",
167-
"^tests/test_domains/test_domain_py\\.py$",
168-
"^tests/test_domains/test_domain_py_fields\\.py$",
169-
"^tests/test_domains/test_domain_py_pyfunction\\.py$",
170-
"^tests/test_domains/test_domain_py_pyobject\\.py$",
171-
"^tests/test_domains/test_domain_rst\\.py$",
172-
"^tests/test_domains/test_domain_std\\.py$",
173-
# tests/test_environment
174-
"^tests/test_environment/test_environment_toctree\\.py$",
175-
# tests/test_extensions
176-
"^tests/test_extensions/test_ext_apidoc\\.py$",
177-
"^tests/test_extensions/test_ext_autodoc\\.py$",
178-
"^tests/test_extensions/test_ext_autodoc_events\\.py$",
179-
"^tests/test_extensions/test_ext_autodoc_mock\\.py$",
180-
"^tests/test_extensions/test_ext_autosummary\\.py$",
181-
"^tests/test_extensions/test_ext_doctest\\.py$",
182-
"^tests/test_extensions/test_ext_inheritance_diagram\\.py$",
183-
"^tests/test_extensions/test_ext_intersphinx\\.py$",
184-
"^tests/test_extensions/test_ext_napoleon_docstring\\.py$",
185-
# tests/test_intl
186-
"^tests/test_intl/test_intl\\.py$",
187-
# tests/test_pycode
188-
"^tests/test_pycode/test_pycode\\.py$",
189-
"^tests/test_pycode/test_pycode_ast\\.py$",
190-
# tests/test_transforms
191-
"^tests/test_transforms/test_transforms_post_transforms\\.py$",
192-
# tests/test_util
193-
"^tests/test_util/test_util_fileutil\\.py$",
194-
"^tests/test_util/test_util_i18n\\.py$",
195-
"^tests/test_util/test_util_inspect\\.py$",
196-
"^tests/test_util/test_util_logging\\.py$",
197-
"^tests/test_util/test_util_nodes\\.py$",
198-
"^tests/test_util/test_util_rst\\.py$",
199-
"^tests/test_util/test_util_template\\.py$",
200-
"^tests/test_util/test_util_typing\\.py$",
201-
"^tests/test_util/typing_test_data\\.py$",
202149
]
203150
python_version = "3.11"
204151
strict = true
@@ -231,6 +178,7 @@ strict_optional = false
231178
module = [
232179
"imagesize",
233180
"pypi_attestations",
181+
"pyximport",
234182
"sigstore.models",
235183
"sigstore.verify",
236184
"sigstore.verify.policy",
@@ -351,6 +299,73 @@ module = [
351299
]
352300
disallow_untyped_defs = false
353301

302+
[[tool.mypy.overrides]]
303+
module = [
304+
# tests/
305+
"tests.test_quickstart",
306+
"tests.test_search",
307+
# tests/test_builders
308+
"tests.test_builders.test_build_epub",
309+
"tests.test_builders.test_build_gettext",
310+
"tests.test_builders.test_build_latex",
311+
"tests.test_builders.test_build_texinfo",
312+
# tests/test_config
313+
"tests.test_config.test_config",
314+
# tests/test_directives
315+
"tests.test_directives.test_directive_only",
316+
"tests.test_directives.test_directive_other",
317+
"tests.test_directives.test_directive_patch",
318+
# tests/test_domains
319+
"tests.test_domains.test_domain_c",
320+
"tests.test_domains.test_domain_cpp",
321+
"tests.test_domains.test_domain_js",
322+
"tests.test_domains.test_domain_py",
323+
"tests.test_domains.test_domain_py_fields",
324+
"tests.test_domains.test_domain_py_pyfunction",
325+
"tests.test_domains.test_domain_py_pyobject",
326+
"tests.test_domains.test_domain_rst",
327+
"tests.test_domains.test_domain_std",
328+
# tests/test_environment
329+
"tests.test_environment.test_environment_toctree",
330+
# tests/test_extensions
331+
"tests.test_extensions.test_ext_apidoc",
332+
"tests.test_extensions.test_ext_autodoc",
333+
"tests.test_extensions.test_ext_autodoc_events",
334+
"tests.test_extensions.test_ext_autodoc_mock",
335+
"tests.test_extensions.test_ext_autosummary",
336+
"tests.test_extensions.test_ext_doctest",
337+
"tests.test_extensions.test_ext_inheritance_diagram",
338+
"tests.test_extensions.test_ext_intersphinx",
339+
"tests.test_extensions.test_ext_napoleon_docstring",
340+
# tests/test_intl
341+
"tests.test_intl.test_intl",
342+
# tests/test_pycode
343+
"tests.test_pycode.test_pycode",
344+
"tests.test_pycode.test_pycode_ast",
345+
# tests/test_transforms
346+
"tests.test_transforms.test_transforms_post_transforms",
347+
# tests/test_util
348+
"tests.test_util.test_util_fileutil",
349+
"tests.test_util.test_util_i18n",
350+
"tests.test_util.test_util_inspect",
351+
"tests.test_util.test_util_logging",
352+
"tests.test_util.test_util_nodes",
353+
"tests.test_util.test_util_rst",
354+
"tests.test_util.test_util_template",
355+
"tests.test_util.test_util_typing",
356+
]
357+
check_untyped_defs = false
358+
disable_error_code = [
359+
"annotation-unchecked",
360+
]
361+
disallow_incomplete_defs = false
362+
disallow_untyped_calls = false
363+
disallow_untyped_defs = false
364+
365+
[[tool.mypy.overrides]]
366+
module = ["tests.test_util.typing_test_data"]
367+
ignore_errors = true
368+
354369
[tool.pytest.ini_options]
355370
minversion = "6.0"
356371
addopts = [

tests/test_config/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def check(
216216
assert v.__class__ is u.__class__
217217
for u_i, v_i in zip(u, v, strict=True):
218218
counter[type(u)] += 1
219-
check(u_i, v_i, counter=counter, guard=guard | {id(u), id(v)})
219+
check(u_i, v_i, counter=counter, guard=guard | {id(u), id(v)}) # type: ignore[arg-type]
220220

221221
return counter
222222

@@ -280,7 +280,7 @@ def check(
280280
assert v.__class__ is u.__class__
281281
for u_i, v_i in zip(u, v, strict=True):
282282
counter[type(u)] += 1
283-
check(u[u_i], v[v_i], counter=counter, guard=guard | {id(u), id(v)})
283+
check(u[u_i], v[v_i], counter=counter, guard=guard | {id(u), id(v)}) # type: ignore[arg-type]
284284
return counter
285285

286286
counters = check(actual.x, x, counter=Counter())

tests/test_extensions/test_ext_autodoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def process_signature(*args):
320320

321321
app.connect('autodoc-process-signature', process_signature)
322322

323-
def func(x: int, y: int) -> int:
323+
def func(x: int, y: int) -> int: # type: ignore[empty-body]
324324
pass
325325

326326
directive = make_directive_bridge(app.env)

tests/test_extensions/test_ext_autodoc_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_cut_lines_no_objtype():
7171
]
7272
process = cut_lines(2)
7373

74-
process(None, 'function', 'func', None, {}, docstring_lines) # type: ignore[arg-type]
74+
process(None, 'function', 'func', None, {}, docstring_lines)
7575
assert docstring_lines == [
7676
'second line',
7777
'---',

tests/test_extensions/test_ext_autosummary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_escaping(app):
240240

241241
@pytest.mark.sphinx('html', testroot='ext-autosummary')
242242
def test_autosummary_generate_content_for_module(app):
243-
import autosummary_dummy_module
243+
import autosummary_dummy_module # type: ignore[import-not-found]
244244

245245
template = Mock()
246246

@@ -457,7 +457,7 @@ def test_autosummary_generate_content_for_module_imported_members(app):
457457

458458
@pytest.mark.sphinx('html', testroot='ext-autosummary')
459459
def test_autosummary_generate_content_for_module_imported_members_inherited_module(app):
460-
import autosummary_dummy_inherited_module
460+
import autosummary_dummy_inherited_module # type: ignore[import-not-found]
461461

462462
template = Mock()
463463

tests/test_extensions/test_ext_doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def cleanup_call():
7575
cleanup_called += 1
7676

7777

78-
recorded_calls = Counter()
78+
recorded_calls: Counter[tuple[str, str, int]] = Counter()
7979

8080

8181
@pytest.mark.sphinx('doctest', testroot='ext-doctest-skipif')

tests/test_extensions/test_ext_inheritance_diagram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_import_classes(rootdir):
327327
saved_path = sys.path.copy()
328328
sys.path.insert(0, str(rootdir / 'test-ext-inheritance_diagram'))
329329
try:
330-
from example.sphinx import DummyClass
330+
from example.sphinx import DummyClass # type: ignore[import-not-found]
331331

332332
# got exception for unknown class or module
333333
with pytest.raises(InheritanceException):

tests/test_extensions/test_ext_intersphinx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from tests.utils import http_server
3939

4040

41-
class FakeList(list): # NoQA: FURB189
41+
class FakeList(list[str]):
4242
def __iter__(self) -> NoReturn:
4343
raise NotImplementedError
4444

tests/test_intl/test_intl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from sphinx.util.nodes import NodeMatcher
2424

2525
if TYPE_CHECKING:
26+
from collections.abc import Iterator
2627
from io import StringIO
2728
from pathlib import Path
2829

@@ -825,7 +826,7 @@ def sleep(self, ds: float) -> None:
825826

826827

827828
@pytest.fixture
828-
def mock_time_and_i18n() -> tuple[pytest.MonkeyPatch, _MockClock]:
829+
def mock_time_and_i18n() -> Iterator[tuple[pytest.MonkeyPatch, _MockClock]]:
829830
from sphinx.util.i18n import CatalogInfo
830831

831832
# save the 'original' definition
@@ -838,6 +839,7 @@ def mock_write_mo(self, locale, use_fuzzy=False):
838839

839840
# see: https://github.com/pytest-dev/pytest/issues/363
840841
with pytest.MonkeyPatch.context() as mock:
842+
clock: _MockClock
841843
if os.name == 'posix':
842844
clock = _MockUnixClock()
843845
else:

tests/test_search.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from tests.utils import TESTS_ROOT
1717

1818
if TYPE_CHECKING:
19-
from collections.abc import Iterator
19+
from collections.abc import Iterable, Iterator
2020
from pathlib import Path
2121
from typing import Any
2222

@@ -53,12 +53,14 @@ def __str__(self) -> str:
5353

5454

5555
class DummyDomain:
56-
def __init__(self, name: str, data: dict) -> None:
56+
def __init__(
57+
self, name: str, data: Iterable[tuple[str, str, str, str, str, int]]
58+
) -> None:
5759
self.name = name
5860
self.data = data
5961
self.object_types: dict[str, ObjType] = {}
6062

61-
def get_objects(self) -> list[tuple[str, str, str, str, str, int]]:
63+
def get_objects(self) -> Iterable[tuple[str, str, str, str, str, int]]:
6264
return self.data
6365

6466

tests/test_transforms/test_transforms_post_transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def mark_node(self, node: nodes.Node) -> NoReturn:
173173
visitor_methods = {f'visit_{tp.__name__}' for tp in desc_sig_elements_list}
174174
visitor_methods.update(f'visit_{name}' for name in add_visitor_method_for)
175175
class_dict = dict.fromkeys(visitor_methods, BaseCustomTranslatorClass.mark_node)
176-
return type('CustomTranslatorClass', (BaseCustomTranslatorClass,), class_dict) # type: ignore[return-value]
176+
return type('CustomTranslatorClass', (BaseCustomTranslatorClass,), class_dict)
177177

178178
@pytest.mark.parametrize(
179179
'add_visitor_method_for',
@@ -266,7 +266,7 @@ def test_custom_implementation(
266266
strict=True,
267267
):
268268
assert_node(node, node_type)
269-
assert not node.hasattr('_sig_node_type')
269+
assert not hasattr(node, '_sig_node_type')
270270
assert mess == f'mark: {node_type.__name__!r}'
271271
else:
272272
# desc_sig_* nodes are converted into inline nodes

tests/test_util/test_util_inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ def test_isattributedescriptor():
890890
try:
891891
# _testcapi module cannot be importable in some distro
892892
# refs: https://github.com/sphinx-doc/sphinx/issues/9868
893-
import _testcapi
893+
import _testcapi # type: ignore[import-not-found]
894894

895895
# instancemethod (C-API)
896896
testinstancemethod = _testcapi.instancemethod(str.__repr__)

0 commit comments

Comments
 (0)