diff --git a/tests/test_extensions/test_ext_autosummary.py b/tests/test_extensions/test_ext_autosummary.py index d1ea3d1ac..a6bf97a22 100644 --- a/tests/test_extensions/test_ext_autosummary.py +++ b/tests/test_extensions/test_ext_autosummary.py @@ -3,6 +3,7 @@ import sys from io import StringIO from unittest.mock import Mock, patch +from xml.etree.ElementTree import Element import pytest from docutils import nodes @@ -45,7 +46,7 @@ def _unload_target_module(): def test_mangle_signature(): - TEST = """ + TEST_SIGNATURE = """ () :: () (a, b, c, d, e) :: (a, b, c, d, e) (a, b, c=1, d=2, e=3) :: (a, b[, c, d, e]) @@ -66,7 +67,11 @@ def test_mangle_signature(): (a: Tuple[int, str], b: int) -> str :: (a, b) """ - TEST = [[y.strip() for y in x.split('::')] for x in TEST.split('\n') if '::' in x] + TEST = [ + list(map(str.strip, x.split('::'))) + for x in TEST_SIGNATURE.split('\n') + if '::' in x + ] for inp, outp in TEST: res = mangle_signature(inp).strip().replace('\u00a0', ' ') assert res == outp, f"'{inp}' -> '{res}' != '{outp}'" @@ -206,7 +211,7 @@ def test_get_items_summary(make_app, app_params): assert autosummary_items['func'] == func_attrs -def str_content(elem): +def str_content(elem: Element) -> str: if elem.text is not None: return elem.text else: diff --git a/tests/test_extensions/test_ext_napoleon.py b/tests/test_extensions/test_ext_napoleon.py index 1175d6bec..9fd9c2d12 100644 --- a/tests/test_extensions/test_ext_napoleon.py +++ b/tests/test_extensions/test_ext_napoleon.py @@ -2,6 +2,7 @@ import functools from collections import namedtuple +from typing import Any from unittest import mock import pytest @@ -141,7 +142,14 @@ class TestSetup: class TestSkipMember: - def assert_skip(self, what, member, obj, expect_default_skip, config_name): + def assert_skip( + self, + what: str, + member: str, + obj: Any, + expect_default_skip: bool, + config_name: str, + ) -> None: skip = True app = mock.Mock() app.config = Config() diff --git a/tests/test_util/test_util_nodes.py b/tests/test_util/test_util_nodes.py index 800dcc2b6..a330eff36 100644 --- a/tests/test_util/test_util_nodes.py +++ b/tests/test_util/test_util_nodes.py @@ -4,7 +4,7 @@ from __future__ import annotations import warnings from textwrap import dedent -from typing import Any +from typing import TYPE_CHECKING, Any import pytest from docutils import frontend, nodes @@ -21,12 +21,15 @@ from sphinx.util.nodes import ( split_explicit_title, ) +if TYPE_CHECKING: + from docutils.nodes import document -def _transform(doctree): + +def _transform(doctree) -> None: ApplySourceWorkaround(doctree).apply() -def create_new_document(): +def create_new_document() -> document: with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=DeprecationWarning) # DeprecationWarning: The frontend.OptionParser class will be replaced @@ -44,7 +47,7 @@ def _get_doctree(text): return document -def assert_node_count(messages, node_type, expect_count): +def assert_node_count(messages, node_type, expect_count) -> None: count = 0 node_list = [node for node, msg in messages] for node in node_list: