Skip to content

Commit 693f58e

Browse files
committed
Remove some entries from the mypy whitelist
1 parent 9257a4f commit 693f58e

File tree

12 files changed

+376
-249
lines changed

12 files changed

+376
-249
lines changed

pyproject.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,11 @@ module = [
230230
"tests.test_domains.test_domain_py_fields",
231231
"tests.test_domains.test_domain_py_pyfunction",
232232
"tests.test_domains.test_domain_py_pyobject",
233-
"tests.test_domains.test_domain_rst",
234233
"tests.test_domains.test_domain_std",
235234
# tests/test_environment
236235
"tests.test_environment.test_environment_toctree",
237236
# tests/test_ext_autodoc
238237
"tests.test_ext_autodoc.test_ext_autodoc",
239-
"tests.test_ext_autodoc.test_ext_autodoc_events",
240238
"tests.test_ext_autodoc.test_ext_autodoc_mock",
241239
# tests/test_ext_autosummary
242240
"tests.test_ext_autosummary.test_ext_autosummary",
@@ -246,14 +244,9 @@ module = [
246244
"tests.test_ext_napoleon.test_ext_napoleon_docstring",
247245
# tests/test_extensions
248246
"tests.test_extensions.test_ext_apidoc",
249-
"tests.test_extensions.test_ext_doctest",
250247
"tests.test_extensions.test_ext_inheritance_diagram",
251-
# tests/test_intl
252-
"tests.test_intl.test_intl",
253248
# tests/test_util
254-
"tests.test_util.test_util_i18n",
255249
"tests.test_util.test_util_inspect",
256-
"tests.test_util.test_util_logging",
257250
"tests.test_util.test_util_nodes",
258251
"tests.test_util.test_util_typing",
259252
]

sphinx/ext/autodoc/_event_listeners.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __call__(
7474
skip: bool,
7575
options: Any,
7676
/,
77-
) -> bool: ...
77+
) -> bool | None: ...
7878

7979

8080
def cut_lines(

sphinx/ext/doctest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ def __del__(self) -> None:
336336
if hasattr(self, 'outfile'):
337337
self.outfile.close()
338338

339-
def _out(self, text: str) -> None:
339+
def _out(self, text: str, /) -> None:
340340
logger.info(text, nonl=True)
341341
self.outfile.write(text)
342342

343-
def _warn_out(self, text: str) -> None:
343+
def _warn_out(self, text: str, /) -> None:
344344
if self.config.verbosity < 0:
345345
logger.warning(text)
346346
else:

sphinx/util/i18n.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def docname_to_domain(docname: str, compaction: bool | str) -> str:
218218

219219

220220
def babel_format_date(
221-
date: datetime,
221+
date: dt.datetime,
222222
format: str,
223223
locale: str,
224224
formatter: Formatter = babel.dates.format_date,

tests/test_domains/test_domain_rst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def test_rst_directive_option_type(app: SphinxTestApp) -> None:
225225

226226

227227
@pytest.mark.sphinx('html', testroot='_blank')
228-
def test_rst_directive_and_directive_option(app):
228+
def test_rst_directive_and_directive_option(app: SphinxTestApp) -> None:
229229
text = '.. rst:directive:: foo\n\n .. rst:directive:option:: bar\n'
230230
doctree = restructuredtext.parse(app, text)
231231
assert_node(

tests/test_ext_autodoc/test_ext_autodoc_events.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,32 @@
22

33
from __future__ import annotations
44

5+
from typing import TYPE_CHECKING
6+
57
import pytest
68

79
from sphinx.ext.autodoc import between, cut_lines
810

911
from tests.test_ext_autodoc.autodoc_util import FakeEvents, do_autodoc
1012

13+
if TYPE_CHECKING:
14+
from typing import Any
15+
16+
from sphinx.application import Sphinx
17+
from sphinx.ext.autodoc._property_types import _AutodocObjType
18+
1119
pytestmark = pytest.mark.usefixtures('inject_autodoc_root_into_sys_path')
1220

1321

1422
def test_process_docstring() -> None:
15-
def on_process_docstring(app, what, name, obj, options, lines):
23+
def on_process_docstring(
24+
app: Sphinx,
25+
what: _AutodocObjType,
26+
name: str,
27+
obj: Any,
28+
options: Any,
29+
lines: list[str],
30+
) -> None:
1631
lines.clear()
1732
lines.append('my docstring')
1833

@@ -31,7 +46,14 @@ def on_process_docstring(app, what, name, obj, options, lines):
3146

3247

3348
def test_process_docstring_for_nondatadescriptor() -> None:
34-
def on_process_docstring(app, what, name, obj, options, lines):
49+
def on_process_docstring(
50+
app: Sphinx,
51+
what: _AutodocObjType,
52+
name: str,
53+
obj: Any,
54+
options: Any,
55+
lines: list[str],
56+
) -> None:
3557
raise RuntimeError
3658

3759
events = FakeEvents()
@@ -62,7 +84,7 @@ def test_cut_lines() -> None:
6284
]
6385

6486

65-
def test_cut_lines_no_objtype():
87+
def test_cut_lines_no_objtype() -> None:
6688
docstring_lines = [
6789
'first line',
6890
'---',
@@ -73,7 +95,7 @@ def test_cut_lines_no_objtype():
7395
]
7496
process = cut_lines(2)
7597

76-
process(None, 'function', 'func', None, {}, docstring_lines)
98+
process(None, 'function', 'func', None, {}, docstring_lines) # type: ignore[arg-type]
7799
assert docstring_lines == [
78100
'second line',
79101
'---',
@@ -116,7 +138,14 @@ def test_between_exclude() -> None:
116138

117139

118140
def test_skip_module_member() -> None:
119-
def autodoc_skip_member(app, what, name, obj, skip, options):
141+
def autodoc_skip_member(
142+
app: Sphinx,
143+
what: _AutodocObjType,
144+
name: str,
145+
obj: Any,
146+
skip: bool,
147+
options: Any,
148+
) -> bool | None:
120149
if name == 'Class':
121150
return True # Skip "Class" class in __all__
122151
elif name == 'raises':

tests/test_extensions/test_ext_doctest.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from packaging.specifiers import InvalidSpecifier
1212
from packaging.version import InvalidVersion
1313

14-
from sphinx.ext.doctest import is_allowed_version
14+
from sphinx.ext.doctest import DocTestBuilder, is_allowed_version
1515

1616
if TYPE_CHECKING:
1717
from sphinx.testing.util import SphinxTestApp
@@ -74,12 +74,12 @@ def test_is_allowed_version() -> None:
7474
is_allowed_version('>3.4', 'Sphinx')
7575

7676

77-
def cleanup_call():
77+
def cleanup_call() -> None:
7878
global cleanup_called # NoQA: PLW0603
7979
cleanup_called += 1
8080

8181

82-
recorded_calls: Counter[tuple[str, str, int]] = Counter()
82+
recorded_calls: Counter[tuple[str, str, bool]] = Counter()
8383

8484

8585
@pytest.mark.sphinx('doctest', testroot='ext-doctest-skipif')
@@ -125,16 +125,17 @@ def test_skipif(app: SphinxTestApp) -> None:
125125
}
126126

127127

128-
def record(directive, part, should_skip):
128+
def record(directive: str, part: str, should_skip: bool) -> str:
129129
recorded_calls[directive, part, should_skip] += 1
130130
return f'Recorded {directive} {part} {should_skip}'
131131

132132

133133
@pytest.mark.sphinx('doctest', testroot='ext-doctest-with-autodoc')
134-
def test_reporting_with_autodoc(app, capfd):
134+
def test_reporting_with_autodoc(app: SphinxTestApp) -> None:
135135
# Patch builder to get a copy of the output
136-
written = []
137-
app.builder._warn_out = written.append
136+
written: list[str] = []
137+
assert isinstance(app.builder, DocTestBuilder)
138+
app.builder._warn_out = written.append # type: ignore[method-assign]
138139
app.build(force_all=True)
139140

140141
failures = [
@@ -151,36 +152,43 @@ def test_reporting_with_autodoc(app, capfd):
151152

152153
@pytest.mark.sphinx('doctest', testroot='ext-doctest-fail-fast')
153154
@pytest.mark.parametrize('fail_fast', [False, True, None])
154-
def test_fail_fast(app, fail_fast, capsys):
155+
def test_fail_fast(app: SphinxTestApp, fail_fast: bool | None) -> None:
155156
if fail_fast is not None:
156157
app.config.doctest_fail_fast = fail_fast
157158
# Patch builder to get a copy of the output
158-
written = []
159-
app.builder._out = written.append
159+
written: list[str] = []
160+
assert isinstance(app.builder, DocTestBuilder)
161+
app.builder._out = written.append # type: ignore[method-assign]
160162
app.build(force_all=True)
161163
assert app.statuscode
162164

163-
written = ''.join(written)
165+
written = ''.join(written).split('\n')
164166
if fail_fast:
165-
assert 'Doctest summary (exiting after first failed test)' in written
166-
assert '1 failure in tests' in written
167+
assert written[10] == 'Doctest summary (exiting after first failed test)'
168+
assert written[13] == ' 1 failure in tests'
167169
else:
168-
assert 'Doctest summary\n' in written
169-
assert '2 failures in tests' in written
170+
assert written[10] == 'Doctest summary'
171+
assert written[13] == ' 2 failures in tests'
170172

171173

172174
@pytest.mark.sphinx('doctest', testroot='ext-doctest-with-autodoc')
173175
@pytest.mark.parametrize(
174176
('test_doctest_blocks', 'group_name'),
175-
[(None, 'default'), ('CustomGroupName', 'CustomGroupName')],
177+
[
178+
(None, 'default'),
179+
('CustomGroupName', 'CustomGroupName'),
180+
],
176181
)
177-
def test_doctest_block_group_name(app, test_doctest_blocks, group_name, capfd):
182+
def test_doctest_block_group_name(
183+
app: SphinxTestApp, test_doctest_blocks: str | None, group_name: str
184+
) -> None:
178185
if test_doctest_blocks is not None:
179186
app.config.doctest_test_doctest_blocks = test_doctest_blocks
180187

181188
# Patch builder to get a copy of the output
182-
written = []
183-
app.builder._warn_out = written.append
189+
written: list[str] = []
190+
assert isinstance(app.builder, DocTestBuilder)
191+
app.builder._warn_out = written.append # type: ignore[method-assign]
184192
app.build(force_all=True)
185193

186194
failures = [

0 commit comments

Comments
 (0)