Skip to content

Commit f7fa3ab

Browse files
committed
Do not allow untyped calls anywhere in the mypy config
1 parent a15c149 commit f7fa3ab

File tree

6 files changed

+50
-44
lines changed

6 files changed

+50
-44
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ disable_error_code = [
342342
"annotation-unchecked",
343343
]
344344
disallow_incomplete_defs = false
345-
disallow_untyped_calls = false
346345
disallow_untyped_defs = false
347346

348347
[[tool.mypy.overrides]]

tests/test_builders/test_build_latex.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747

4848
# only run latex if all needed packages are there
49-
def kpsetest(*filenames):
49+
def kpsetest(*filenames: str) -> bool:
5050
try:
5151
subprocess.run(['kpsewhich', *list(filenames)], capture_output=True, check=True) # NoQA: S607
5252
return True
@@ -55,7 +55,7 @@ def kpsetest(*filenames):
5555

5656

5757
# compile latex document with app.config.latex_engine
58-
def compile_latex_document(app, filename='projectnamenotset.tex', docclass='manual'):
58+
def compile_latex_document(app: SphinxTestApp, filename: str = 'projectnamenotset.tex', docclass: str = 'manual') -> None:
5959
# now, try to run latex over it
6060
try:
6161
with chdir(app.outdir):
@@ -1570,7 +1570,7 @@ def test_latex_table_tabulars(app: SphinxTestApp) -> None:
15701570
content = re.sub(r'\\sphinxstepscope', '', content) # filter a separator
15711571
tables[sectname] = content.strip()
15721572

1573-
def get_expected(name):
1573+
def get_expected(name: str) -> str:
15741574
return (
15751575
(app.srcdir / 'expects' / (name + '.tex'))
15761576
.read_text(encoding='utf8')
@@ -1648,7 +1648,7 @@ def test_latex_table_longtable(app: SphinxTestApp) -> None:
16481648
content = re.sub(r'\\sphinxstepscope', '', content) # filter a separator
16491649
tables[sectname] = content.strip()
16501650

1651-
def get_expected(name):
1651+
def get_expected(name: str) -> str:
16521652
return (
16531653
(app.srcdir / 'expects' / (name + '.tex'))
16541654
.read_text(encoding='utf8')
@@ -1715,7 +1715,7 @@ def test_latex_table_complex_tables(app: SphinxTestApp) -> None:
17151715
sectname, _, content = chap.partition('}')
17161716
tables[sectname] = content.strip()
17171717

1718-
def get_expected(name):
1718+
def get_expected(name: str) -> str:
17191719
return (
17201720
(app.srcdir / 'expects' / (name + '.tex'))
17211721
.read_text(encoding='utf8')

tests/test_domains/test_domain_c.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from sphinx.writers.text import STDINDENT
3333

3434
if TYPE_CHECKING:
35+
from collections.abc import Generator
3536
from io import StringIO
3637

3738

@@ -41,15 +42,15 @@ class Config:
4142
c_extra_keywords = _macro_keywords
4243

4344

44-
def parse(name, string):
45-
parser = DefinitionParser(string, location=None, config=Config())
45+
def parse(name: str, string: str):
46+
parser = DefinitionParser(string, location=None, config=Config()) # type: ignore[arg-type]
4647
parser.allowFallbackExpressionParsing = False
4748
ast = parser.parse_declaration(name, name)
4849
parser.assert_end()
4950
return ast
5051

5152

52-
def _check(name, input, id_dict, output, key, as_text_output):
53+
def _check(name: str, input: str, id_dict, output, key, as_text_output):
5354
if key is None:
5455
key = name
5556
key += ' '
@@ -102,14 +103,13 @@ def _check(name, input, id_dict, output, key, as_text_output):
102103
# except NoOldIdError:
103104
# id_actual.append(None)
104105

105-
res = [True]
106-
for i in range(1, _max_id + 1):
107-
res.append(id_expected[i] == id_actual[i])
106+
res_bools = [True]
107+
res_bools.extend(id_expected[i] == id_actual[i] for i in range(1, _max_id + 1))
108108

109-
if not all(res):
109+
if not all(res_bools):
110110
print('input: %s' % input.rjust(20))
111111
for i in range(1, _max_id + 1):
112-
if res[i]:
112+
if res_bools[i]:
113113
continue
114114
print('Error in id version %d.' % i)
115115
print('result: %s' % id_actual[i])
@@ -118,7 +118,7 @@ def _check(name, input, id_dict, output, key, as_text_output):
118118
raise DefinitionError
119119

120120

121-
def check(name, input, id_dict, output=None, key=None, as_text_output=None):
121+
def check(name: str, input, id_dict, output=None, key=None, as_text_output=None) -> None:
122122
if output is None:
123123
output = input
124124
# First, check without semicolon
@@ -136,8 +136,8 @@ def check(name, input, id_dict, output=None, key=None, as_text_output=None):
136136

137137

138138
def test_domain_c_ast_expressions() -> None:
139-
def expr_check(expr, output=None):
140-
parser = DefinitionParser(expr, location=None, config=Config())
139+
def expr_check(expr: str, output: str | None = None) -> None:
140+
parser = DefinitionParser(expr, location=None, config=Config()) # type: ignore[arg-type]
141141
parser.allowFallbackExpressionParsing = False
142142
ast = parser.parse_expression()
143143
parser.assert_end()
@@ -337,8 +337,8 @@ def expr_check(expr, output=None):
337337

338338

339339
def test_domain_c_ast_fundamental_types() -> None:
340-
def types():
341-
def signed(t):
340+
def types() -> Generator[str]:
341+
def signed(t: str) -> Generator[str]:
342342
yield t
343343
yield 'signed ' + t
344344
yield 'unsigned ' + t

tests/test_domains/test_domain_cpp.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,25 @@
3535
if TYPE_CHECKING:
3636
from io import StringIO
3737

38+
from sphinx.domains.cpp._ast import ASTDeclaration
3839

39-
def parse(name, string):
40+
41+
def parse(name: str, string: str) -> ASTDeclaration:
4042
class Config:
4143
cpp_id_attributes = ['id_attr']
4244
cpp_paren_attributes = ['paren_attr']
4345

44-
parser = DefinitionParser(string, location=None, config=Config())
46+
parser = DefinitionParser(string, location=None, config=Config()) # type: ignore[arg-type]
4547
parser.allowFallbackExpressionParsing = False
4648
ast = parser.parse_declaration(name, name)
4749
parser.assert_end()
4850
# The scopedness would usually have been set by CPPEnumObject
4951
if name == 'enum':
50-
ast.scoped = None # simulate unscoped enum
52+
ast.scoped = None # type: ignore[attr-defined] # simulate unscoped enum
5153
return ast
5254

5355

54-
def _check(name, input, id_dict, output, key, as_text_output):
56+
def _check(name, input: str, id_dict: dict[int, str], output, key, as_text_output):
5557
if key is None:
5658
key = name
5759
key += ' '
@@ -80,7 +82,7 @@ def _check(name, input, id_dict, output, key, as_text_output):
8082
parent_node = addnodes.desc()
8183
signode = addnodes.desc_signature(input, '')
8284
parent_node += signode
83-
ast.describe_signature(signode, 'lastIsName', symbol, options={})
85+
ast.describe_signature(signode, 'lastIsName', symbol, options={}) # type: ignore[arg-type]
8486
res_as_text = parent_node.astext()
8587
if res_as_text != output_as_text:
8688
print()
@@ -90,13 +92,13 @@ def _check(name, input, id_dict, output, key, as_text_output):
9092
print('Node:', parent_node)
9193
raise DefinitionError
9294

93-
id_expected = [None]
95+
id_expected: list[str | None] = [None]
9496
for i in range(1, _max_id + 1):
9597
if i in id_dict:
9698
id_expected.append(id_dict[i])
9799
else:
98100
id_expected.append(id_expected[i - 1])
99-
id_actual = [None]
101+
id_actual: list[str | None] = [None]
100102
for i in range(1, _max_id + 1):
101103
try:
102104
id = ast.get_id(version=i)
@@ -105,14 +107,14 @@ def _check(name, input, id_dict, output, key, as_text_output):
105107
except NoOldIdError:
106108
id_actual.append(None)
107109

108-
res = [True]
110+
res_bools = [True]
109111
for i in range(1, _max_id + 1):
110-
res.append(id_expected[i] == id_actual[i])
112+
res_bools.append(id_expected[i] == id_actual[i])
111113

112-
if not all(res):
114+
if not all(res_bools):
113115
print('input: %s' % input.rjust(20))
114116
for i in range(1, _max_id + 1):
115-
if res[i]:
117+
if res_bools[i]:
116118
continue
117119
print('Error in id version %d.' % i)
118120
print('result: %s' % id_actual[i])
@@ -121,7 +123,7 @@ def _check(name, input, id_dict, output, key, as_text_output):
121123
raise DefinitionError
122124

123125

124-
def check(name, input, id_dict, output=None, key=None, as_text_output=None):
126+
def check(name: str, input: str, id_dict: dict[int, str], output=None, key=None, as_text_output=None) -> None:
125127
if output is None:
126128
output = input
127129
# First, check without semicolon
@@ -177,7 +179,7 @@ def make_id_v2():
177179

178180

179181
def test_domain_cpp_ast_expressions() -> None:
180-
def expr_check(expr, id, id4=None):
182+
def expr_check(expr: str, id: str, id4: str | None = None):
181183
ids = 'IE1CIA%s_1aE'
182184
# call .format() on the expr to unescape double curly braces
183185
id_dict = {2: ids % expr.format(), 3: ids % id}
@@ -189,7 +191,7 @@ class Config:
189191
cpp_id_attributes = ['id_attr']
190192
cpp_paren_attributes = ['paren_attr']
191193

192-
parser = DefinitionParser(expr, location=None, config=Config())
194+
parser = DefinitionParser(expr, location=None, config=Config()) # type: ignore[arg-type]
193195
parser.allowFallbackExpressionParsing = False
194196
ast = parser.parse_expression()
195197
res = str(ast)
@@ -1472,12 +1474,12 @@ def test_domain_cpp_ast_attributes() -> None:
14721474
check('enumerator', '{key}Foo [[attr1]] [[attr2]] = 42', {2: '3Foo'})
14731475

14741476

1475-
def check_ast_xref_parsing(target):
1477+
def check_ast_xref_parsing(target: str) -> None:
14761478
class Config:
14771479
cpp_id_attributes = ['id_attr']
14781480
cpp_paren_attributes = ['paren_attr']
14791481

1480-
parser = DefinitionParser(target, location='', config=Config())
1482+
parser = DefinitionParser(target, location='', config=Config()) # type: ignore[arg-type]
14811483
parser.parse_xref_object()
14821484
parser.assert_end()
14831485

@@ -1518,6 +1520,8 @@ def test_domain_cpp_ast_xref_parsing() -> None:
15181520
def test_domain_cpp_template_parameters_is_pack(param: str, is_pack: bool):
15191521
def parse_template_parameter(param: str):
15201522
ast = parse('type', 'template<' + param + '> X')
1523+
assert ast.templatePrefix is not None
1524+
assert ast.templatePrefix.templates is not None
15211525
return ast.templatePrefix.templates[0].params[0]
15221526

15231527
ast = parse_template_parameter(param)

tests/test_extensions/test_ext_intersphinx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __iter__(self) -> NoReturn:
5151
raise NotImplementedError
5252

5353

54-
def fake_node(domain, type, target, content, **attrs):
54+
def fake_node(domain: str, type: str, target: str, content: str, **attrs) -> tuple[addnodes.pending_xref, nodes.emphasis]:
5555
contnode = nodes.emphasis(content, content)
5656
node = addnodes.pending_xref('')
5757
node['reftarget'] = target
@@ -62,12 +62,12 @@ def fake_node(domain, type, target, content, **attrs):
6262
return node, contnode
6363

6464

65-
def reference_check(app, *args, **kwds):
65+
def reference_check(app: SphinxTestApp, *args, **kwds):
6666
node, contnode = fake_node(*args, **kwds)
6767
return missing_reference(app, app.env, node, contnode)
6868

6969

70-
def set_config(app, mapping):
70+
def set_config(app: SphinxTestApp, mapping: dict[str, tuple[str, str | list[str]]]) -> None:
7171
# copy *mapping* so that normalization does not alter it
7272
app.config.intersphinx_mapping = mapping.copy()
7373
app.config.intersphinx_cache_limit = 0
@@ -544,7 +544,7 @@ def test_validate_intersphinx_mapping_warnings(app: SphinxTestApp) -> None:
544544
'good-target-1': ('e.example', None), # valid inventory location (None)
545545
'good-target-2': ('f.example', ('x',)), # valid inventory location (sequence input)
546546
} # fmt: skip
547-
set_config(app, bad_intersphinx_mapping)
547+
set_config(app, bad_intersphinx_mapping) # type: ignore[arg-type]
548548

549549
# normalise the inventory and check if it's done correctly
550550
with pytest.raises(

tests/test_util/test_util_inspect.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import functools
99
import types
1010
from inspect import Parameter
11-
from typing import Callable, List, Optional, Union # NoQA: UP035
11+
from typing import TYPE_CHECKING, Callable, List, Optional, Union # NoQA: UP035
1212

1313
import pytest
1414

@@ -20,6 +20,9 @@
2020
)
2121
from sphinx.util.typing import stringify_annotation
2222

23+
if TYPE_CHECKING:
24+
from typing import Any
25+
2326

2427
class Base:
2528
def meth(self):
@@ -98,7 +101,7 @@ def __call__(self):
98101
pass
99102

100103

101-
def _decorator(f):
104+
def _decorator(f: Callable[[], Any]) -> Callable[[], Any]:
102105
@functools.wraps(f)
103106
def wrapper():
104107
return f()
@@ -658,10 +661,10 @@ def test_recursive_collection_description():
658661

659662
def test_dict_customtype() -> None:
660663
class CustomType:
661-
def __init__(self, value):
664+
def __init__(self, value: int) -> None:
662665
self._value = value
663666

664-
def __repr__(self):
667+
def __repr__(self) -> str:
665668
return '<CustomType(%r)>' % self._value
666669

667670
dictionary = {CustomType(2): 2, CustomType(1): 1}
@@ -986,7 +989,7 @@ def my_method(self):
986989
assert not inspect.is_builtin_class_method(4, 'still does not crash')
987990

988991
class ObjectWithMroAttr:
989-
def __init__(self, mro_attr):
992+
def __init__(self, mro_attr: list[int]) -> None:
990993
self.__mro__ = mro_attr
991994

992995
assert not inspect.is_builtin_class_method(

0 commit comments

Comments
 (0)