mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Move mypy test module exclusions to per-module ignores (#13265)
This commit is contained in:
@@ -216,7 +216,7 @@ def test_config_pickle_circular_reference_in_list():
|
||||
assert v.__class__ is u.__class__
|
||||
for u_i, v_i in zip(u, v, strict=True):
|
||||
counter[type(u)] += 1
|
||||
check(u_i, v_i, counter=counter, guard=guard | {id(u), id(v)})
|
||||
check(u_i, v_i, counter=counter, guard=guard | {id(u), id(v)}) # type: ignore[arg-type]
|
||||
|
||||
return counter
|
||||
|
||||
@@ -280,7 +280,7 @@ def test_config_pickle_circular_reference_in_dict():
|
||||
assert v.__class__ is u.__class__
|
||||
for u_i, v_i in zip(u, v, strict=True):
|
||||
counter[type(u)] += 1
|
||||
check(u[u_i], v[v_i], counter=counter, guard=guard | {id(u), id(v)})
|
||||
check(u[u_i], v[v_i], counter=counter, guard=guard | {id(u), id(v)}) # type: ignore[arg-type]
|
||||
return counter
|
||||
|
||||
counters = check(actual.x, x, counter=Counter())
|
||||
|
@@ -320,7 +320,7 @@ def test_autodoc_process_signature_typehints(app):
|
||||
|
||||
app.connect('autodoc-process-signature', process_signature)
|
||||
|
||||
def func(x: int, y: int) -> int:
|
||||
def func(x: int, y: int) -> int: # type: ignore[empty-body]
|
||||
pass
|
||||
|
||||
directive = make_directive_bridge(app.env)
|
||||
|
@@ -71,7 +71,7 @@ def test_cut_lines_no_objtype():
|
||||
]
|
||||
process = cut_lines(2)
|
||||
|
||||
process(None, 'function', 'func', None, {}, docstring_lines) # type: ignore[arg-type]
|
||||
process(None, 'function', 'func', None, {}, docstring_lines)
|
||||
assert docstring_lines == [
|
||||
'second line',
|
||||
'---',
|
||||
|
@@ -240,7 +240,7 @@ def test_escaping(app):
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autosummary')
|
||||
def test_autosummary_generate_content_for_module(app):
|
||||
import autosummary_dummy_module
|
||||
import autosummary_dummy_module # type: ignore[import-not-found]
|
||||
|
||||
template = Mock()
|
||||
|
||||
@@ -457,7 +457,7 @@ def test_autosummary_generate_content_for_module_imported_members(app):
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autosummary')
|
||||
def test_autosummary_generate_content_for_module_imported_members_inherited_module(app):
|
||||
import autosummary_dummy_inherited_module
|
||||
import autosummary_dummy_inherited_module # type: ignore[import-not-found]
|
||||
|
||||
template = Mock()
|
||||
|
||||
|
@@ -75,7 +75,7 @@ def cleanup_call():
|
||||
cleanup_called += 1
|
||||
|
||||
|
||||
recorded_calls = Counter()
|
||||
recorded_calls: Counter[tuple[str, str, int]] = Counter()
|
||||
|
||||
|
||||
@pytest.mark.sphinx('doctest', testroot='ext-doctest-skipif')
|
||||
|
@@ -327,7 +327,7 @@ def test_import_classes(rootdir):
|
||||
saved_path = sys.path.copy()
|
||||
sys.path.insert(0, str(rootdir / 'test-ext-inheritance_diagram'))
|
||||
try:
|
||||
from example.sphinx import DummyClass
|
||||
from example.sphinx import DummyClass # type: ignore[import-not-found]
|
||||
|
||||
# got exception for unknown class or module
|
||||
with pytest.raises(InheritanceException):
|
||||
|
@@ -38,7 +38,7 @@ from tests.test_util.intersphinx_data import (
|
||||
from tests.utils import http_server
|
||||
|
||||
|
||||
class FakeList(list): # NoQA: FURB189
|
||||
class FakeList(list[str]):
|
||||
def __iter__(self) -> NoReturn:
|
||||
raise NotImplementedError
|
||||
|
||||
|
@@ -23,6 +23,7 @@ from sphinx.testing.util import assert_node, etree_parse
|
||||
from sphinx.util.nodes import NodeMatcher
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterator
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
|
||||
@@ -825,7 +826,7 @@ class _MockUnixClock(_MockClock):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_time_and_i18n() -> tuple[pytest.MonkeyPatch, _MockClock]:
|
||||
def mock_time_and_i18n() -> Iterator[tuple[pytest.MonkeyPatch, _MockClock]]:
|
||||
from sphinx.util.i18n import CatalogInfo
|
||||
|
||||
# save the 'original' definition
|
||||
@@ -838,6 +839,7 @@ def mock_time_and_i18n() -> tuple[pytest.MonkeyPatch, _MockClock]:
|
||||
|
||||
# see: https://github.com/pytest-dev/pytest/issues/363
|
||||
with pytest.MonkeyPatch.context() as mock:
|
||||
clock: _MockClock
|
||||
if os.name == 'posix':
|
||||
clock = _MockUnixClock()
|
||||
else:
|
||||
|
@@ -16,7 +16,7 @@ from sphinx.search import IndexBuilder
|
||||
from tests.utils import TESTS_ROOT
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterator
|
||||
from collections.abc import Iterable, Iterator
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -53,12 +53,14 @@ class DummyEnvironment:
|
||||
|
||||
|
||||
class DummyDomain:
|
||||
def __init__(self, name: str, data: dict) -> None:
|
||||
def __init__(
|
||||
self, name: str, data: Iterable[tuple[str, str, str, str, str, int]]
|
||||
) -> None:
|
||||
self.name = name
|
||||
self.data = data
|
||||
self.object_types: dict[str, ObjType] = {}
|
||||
|
||||
def get_objects(self) -> list[tuple[str, str, str, str, str, int]]:
|
||||
def get_objects(self) -> Iterable[tuple[str, str, str, str, str, int]]:
|
||||
return self.data
|
||||
|
||||
|
||||
|
@@ -173,7 +173,7 @@ class TestSigElementFallbackTransform:
|
||||
visitor_methods = {f'visit_{tp.__name__}' for tp in desc_sig_elements_list}
|
||||
visitor_methods.update(f'visit_{name}' for name in add_visitor_method_for)
|
||||
class_dict = dict.fromkeys(visitor_methods, BaseCustomTranslatorClass.mark_node)
|
||||
return type('CustomTranslatorClass', (BaseCustomTranslatorClass,), class_dict) # type: ignore[return-value]
|
||||
return type('CustomTranslatorClass', (BaseCustomTranslatorClass,), class_dict)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'add_visitor_method_for',
|
||||
@@ -266,7 +266,7 @@ class TestSigElementFallbackTransform:
|
||||
strict=True,
|
||||
):
|
||||
assert_node(node, node_type)
|
||||
assert not node.hasattr('_sig_node_type')
|
||||
assert not hasattr(node, '_sig_node_type')
|
||||
assert mess == f'mark: {node_type.__name__!r}'
|
||||
else:
|
||||
# desc_sig_* nodes are converted into inline nodes
|
||||
|
@@ -890,7 +890,7 @@ def test_isattributedescriptor():
|
||||
try:
|
||||
# _testcapi module cannot be importable in some distro
|
||||
# refs: https://github.com/sphinx-doc/sphinx/issues/9868
|
||||
import _testcapi
|
||||
import _testcapi # type: ignore[import-not-found]
|
||||
|
||||
# instancemethod (C-API)
|
||||
testinstancemethod = _testcapi.instancemethod(str.__repr__)
|
||||
|
@@ -75,7 +75,7 @@ from typing import (
|
||||
)
|
||||
from weakref import WeakSet
|
||||
|
||||
from sphinx.ext.autodoc import mock
|
||||
from sphinx.ext.autodoc.mock import mock
|
||||
from sphinx.util.typing import _INVALID_BUILTIN_CLASSES, restify, stringify_annotation
|
||||
|
||||
|
||||
@@ -472,7 +472,7 @@ def test_restify_type_ForwardRef():
|
||||
restify(list[ForwardRef('MyInt')]) == ':py:class:`list`\\ [:py:class:`MyInt`]'
|
||||
)
|
||||
|
||||
ann_rst = restify(Tuple[dict[ForwardRef('MyInt'), str], list[List[int]]]) # type: ignore[attr-defined]
|
||||
ann_rst = restify(Tuple[dict[ForwardRef('MyInt'), str], list[List[int]]])
|
||||
assert ann_rst == (
|
||||
':py:class:`~typing.Tuple`\\ [:py:class:`dict`\\ [:py:class:`MyInt`, :py:class:`str`], :py:class:`list`\\ [:py:class:`~typing.List`\\ [:py:class:`int`]]]'
|
||||
)
|
||||
@@ -493,14 +493,14 @@ def test_restify_type_Literal():
|
||||
|
||||
|
||||
def test_restify_pep_585():
|
||||
assert restify(list[str]) == ':py:class:`list`\\ [:py:class:`str`]' # type: ignore[attr-defined]
|
||||
ann_rst = restify(dict[str, str]) # type: ignore[attr-defined]
|
||||
assert restify(list[str]) == ':py:class:`list`\\ [:py:class:`str`]'
|
||||
ann_rst = restify(dict[str, str])
|
||||
assert ann_rst == ':py:class:`dict`\\ [:py:class:`str`, :py:class:`str`]'
|
||||
assert restify(tuple[str, ...]) == ':py:class:`tuple`\\ [:py:class:`str`, ...]'
|
||||
assert restify(tuple[str, str, str]) == (
|
||||
':py:class:`tuple`\\ [:py:class:`str`, :py:class:`str`, :py:class:`str`]'
|
||||
)
|
||||
ann_rst = restify(dict[str, tuple[int, ...]]) # type: ignore[attr-defined]
|
||||
ann_rst = restify(dict[str, tuple[int, ...]])
|
||||
assert ann_rst == (
|
||||
':py:class:`dict`\\ '
|
||||
'[:py:class:`str`, :py:class:`tuple`\\ '
|
||||
@@ -548,10 +548,10 @@ def test_restify_Unpack():
|
||||
|
||||
|
||||
def test_restify_type_union_operator():
|
||||
assert restify(int | None) == ':py:class:`int` | :py:obj:`None`' # type: ignore[attr-defined]
|
||||
assert restify(None | int) == ':py:obj:`None` | :py:class:`int`' # type: ignore[attr-defined]
|
||||
assert restify(int | str) == ':py:class:`int` | :py:class:`str`' # type: ignore[attr-defined]
|
||||
ann_rst = restify(int | str | None) # type: ignore[attr-defined]
|
||||
assert restify(int | None) == ':py:class:`int` | :py:obj:`None`'
|
||||
assert restify(None | int) == ':py:obj:`None` | :py:class:`int`'
|
||||
assert restify(int | str) == ':py:class:`int` | :py:class:`str`'
|
||||
ann_rst = restify(int | str | None)
|
||||
assert ann_rst == ':py:class:`int` | :py:class:`str` | :py:obj:`None`'
|
||||
|
||||
|
||||
@@ -564,7 +564,7 @@ def test_restify_broken_type_hints():
|
||||
|
||||
def test_restify_mock():
|
||||
with mock(['unknown']):
|
||||
import unknown
|
||||
import unknown # type: ignore[import-not-found]
|
||||
|
||||
assert restify(unknown) == ':py:class:`unknown`'
|
||||
assert restify(unknown.secret.Class) == ':py:class:`unknown.secret.Class`'
|
||||
@@ -982,8 +982,8 @@ def test_stringify_type_hints_alias():
|
||||
assert stringify_annotation(MyStr, 'fully-qualified-except-typing') == 'str'
|
||||
assert stringify_annotation(MyStr, 'smart') == 'str'
|
||||
|
||||
assert stringify_annotation(MyTuple) == 'Tuple[str, str]' # type: ignore[attr-defined]
|
||||
assert stringify_annotation(MyTuple, 'smart') == '~typing.Tuple[str, str]' # type: ignore[attr-defined]
|
||||
assert stringify_annotation(MyTuple) == 'Tuple[str, str]'
|
||||
assert stringify_annotation(MyTuple, 'smart') == '~typing.Tuple[str, str]'
|
||||
|
||||
|
||||
def test_stringify_type_Literal():
|
||||
@@ -1005,26 +1005,26 @@ def test_stringify_type_Literal():
|
||||
|
||||
|
||||
def test_stringify_type_union_operator():
|
||||
assert stringify_annotation(int | None) == 'int | None' # type: ignore[attr-defined]
|
||||
assert stringify_annotation(int | None, 'smart') == 'int | None' # type: ignore[attr-defined]
|
||||
assert stringify_annotation(int | None) == 'int | None'
|
||||
assert stringify_annotation(int | None, 'smart') == 'int | None'
|
||||
|
||||
assert stringify_annotation(int | str) == 'int | str' # type: ignore[attr-defined]
|
||||
assert stringify_annotation(int | str, 'smart') == 'int | str' # type: ignore[attr-defined]
|
||||
assert stringify_annotation(int | str) == 'int | str'
|
||||
assert stringify_annotation(int | str, 'smart') == 'int | str'
|
||||
|
||||
assert stringify_annotation(int | str | None) == 'int | str | None' # type: ignore[attr-defined]
|
||||
assert stringify_annotation(int | str | None, 'smart') == 'int | str | None' # type: ignore[attr-defined]
|
||||
assert stringify_annotation(int | str | None) == 'int | str | None'
|
||||
assert stringify_annotation(int | str | None, 'smart') == 'int | str | None'
|
||||
|
||||
ann_str = stringify_annotation(
|
||||
int | tuple[dict[str, int | None], list[int | str]] | None
|
||||
)
|
||||
assert ann_str == 'int | tuple[dict[str, int | None], list[int | str]] | None' # type: ignore[attr-defined]
|
||||
assert ann_str == 'int | tuple[dict[str, int | None], list[int | str]] | None'
|
||||
ann_str = stringify_annotation(
|
||||
int | tuple[dict[str, int | None], list[int | str]] | None, 'smart'
|
||||
)
|
||||
assert ann_str == 'int | tuple[dict[str, int | None], list[int | str]] | None' # type: ignore[attr-defined]
|
||||
assert ann_str == 'int | tuple[dict[str, int | None], list[int | str]] | None'
|
||||
|
||||
assert stringify_annotation(int | Struct) == 'int | struct.Struct' # type: ignore[attr-defined]
|
||||
assert stringify_annotation(int | Struct, 'smart') == 'int | ~struct.Struct' # type: ignore[attr-defined]
|
||||
assert stringify_annotation(int | Struct) == 'int | struct.Struct'
|
||||
assert stringify_annotation(int | Struct, 'smart') == 'int | ~struct.Struct'
|
||||
|
||||
|
||||
def test_stringify_broken_type_hints():
|
||||
@@ -1058,16 +1058,16 @@ def test_stringify_type_ForwardRef():
|
||||
ann_str = stringify_annotation(
|
||||
Tuple[dict[ForwardRef('MyInt'), str], list[List[int]]]
|
||||
)
|
||||
assert ann_str == 'Tuple[dict[MyInt, str], list[List[int]]]' # type: ignore[attr-defined]
|
||||
assert ann_str == 'Tuple[dict[MyInt, str], list[List[int]]]'
|
||||
ann_str = stringify_annotation(
|
||||
Tuple[dict[ForwardRef('MyInt'), str], list[List[int]]],
|
||||
'fully-qualified-except-typing',
|
||||
)
|
||||
assert ann_str == 'Tuple[dict[MyInt, str], list[List[int]]]' # type: ignore[attr-defined]
|
||||
assert ann_str == 'Tuple[dict[MyInt, str], list[List[int]]]'
|
||||
ann_str = stringify_annotation(
|
||||
Tuple[dict[ForwardRef('MyInt'), str], list[List[int]]], 'smart'
|
||||
)
|
||||
assert ann_str == '~typing.Tuple[dict[MyInt, str], list[~typing.List[int]]]' # type: ignore[attr-defined]
|
||||
assert ann_str == '~typing.Tuple[dict[MyInt, str], list[~typing.List[int]]]'
|
||||
|
||||
|
||||
def test_stringify_type_hints_paramspec():
|
||||
|
Reference in New Issue
Block a user