Skip to content

Commit 7487e76

Browse files
Resolve a few mypy issues in tests (#12912)
Co-authored-by: Adam Turner <[email protected]>
1 parent 914f3f4 commit 7487e76

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

tests/test_extensions/test_ext_autosummary.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
from io import StringIO
55
from unittest.mock import Mock, patch
6+
from xml.etree.ElementTree import Element
67

78
import pytest
89
from docutils import nodes
@@ -45,7 +46,7 @@ def _unload_target_module():
4546

4647

4748
def test_mangle_signature():
48-
TEST = """
49+
TEST_SIGNATURE = """
4950
() :: ()
5051
(a, b, c, d, e) :: (a, b, c, d, e)
5152
(a, b, c=1, d=2, e=3) :: (a, b[, c, d, e])
@@ -66,7 +67,11 @@ def test_mangle_signature():
6667
(a: Tuple[int, str], b: int) -> str :: (a, b)
6768
"""
6869

69-
TEST = [[y.strip() for y in x.split('::')] for x in TEST.split('\n') if '::' in x]
70+
TEST = [
71+
list(map(str.strip, x.split('::')))
72+
for x in TEST_SIGNATURE.split('\n')
73+
if '::' in x
74+
]
7075
for inp, outp in TEST:
7176
res = mangle_signature(inp).strip().replace('\u00a0', ' ')
7277
assert res == outp, f"'{inp}' -> '{res}' != '{outp}'"
@@ -206,7 +211,7 @@ def handler(app, what, name, obj, options, lines):
206211
assert autosummary_items['func'] == func_attrs
207212

208213

209-
def str_content(elem):
214+
def str_content(elem: Element) -> str:
210215
if elem.text is not None:
211216
return elem.text
212217
else:

tests/test_extensions/test_ext_napoleon.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import functools
44
from collections import namedtuple
5+
from typing import Any
56
from unittest import mock
67

78
import pytest
@@ -141,7 +142,14 @@ def test_add_config_values(self):
141142

142143

143144
class TestSkipMember:
144-
def assert_skip(self, what, member, obj, expect_default_skip, config_name):
145+
def assert_skip(
146+
self,
147+
what: str,
148+
member: str,
149+
obj: Any,
150+
expect_default_skip: bool,
151+
config_name: str,
152+
) -> None:
145153
skip = True
146154
app = mock.Mock()
147155
app.config = Config()

tests/test_util/test_util_nodes.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import warnings
66
from textwrap import dedent
7-
from typing import Any
7+
from typing import TYPE_CHECKING, Any
88

99
import pytest
1010
from docutils import frontend, nodes
@@ -21,12 +21,15 @@
2121
split_explicit_title,
2222
)
2323

24+
if TYPE_CHECKING:
25+
from docutils.nodes import document
2426

25-
def _transform(doctree):
27+
28+
def _transform(doctree) -> None:
2629
ApplySourceWorkaround(doctree).apply()
2730

2831

29-
def create_new_document():
32+
def create_new_document() -> document:
3033
with warnings.catch_warnings():
3134
warnings.filterwarnings('ignore', category=DeprecationWarning)
3235
# DeprecationWarning: The frontend.OptionParser class will be replaced
@@ -44,7 +47,7 @@ def _get_doctree(text):
4447
return document
4548

4649

47-
def assert_node_count(messages, node_type, expect_count):
50+
def assert_node_count(messages, node_type, expect_count) -> None:
4851
count = 0
4952
node_list = [node for node, msg in messages]
5053
for node in node_list:

0 commit comments

Comments
 (0)