Skip to content

Commit 7901b72

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

File tree

6 files changed

+68
-46
lines changed

6 files changed

+68
-46
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: 9 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,11 @@ 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(
59+
app: SphinxTestApp,
60+
filename: str = 'projectnamenotset.tex',
61+
docclass: str = 'manual',
62+
) -> None:
5963
# now, try to run latex over it
6064
try:
6165
with chdir(app.outdir):
@@ -1570,7 +1574,7 @@ def test_latex_table_tabulars(app: SphinxTestApp) -> None:
15701574
content = re.sub(r'\\sphinxstepscope', '', content) # filter a separator
15711575
tables[sectname] = content.strip()
15721576

1573-
def get_expected(name):
1577+
def get_expected(name: str) -> str:
15741578
return (
15751579
(app.srcdir / 'expects' / (name + '.tex'))
15761580
.read_text(encoding='utf8')
@@ -1648,7 +1652,7 @@ def test_latex_table_longtable(app: SphinxTestApp) -> None:
16481652
content = re.sub(r'\\sphinxstepscope', '', content) # filter a separator
16491653
tables[sectname] = content.strip()
16501654

1651-
def get_expected(name):
1655+
def get_expected(name: str) -> str:
16521656
return (
16531657
(app.srcdir / 'expects' / (name + '.tex'))
16541658
.read_text(encoding='utf8')
@@ -1715,7 +1719,7 @@ def test_latex_table_complex_tables(app: SphinxTestApp) -> None:
17151719
sectname, _, content = chap.partition('}')
17161720
tables[sectname] = content.strip()
17171721

1718-
def get_expected(name):
1722+
def get_expected(name: str) -> str:
17191723
return (
17201724
(app.srcdir / 'expects' / (name + '.tex'))
17211725
.read_text(encoding='utf8')

tests/test_domains/test_domain_c.py

Lines changed: 15 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,9 @@ 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(
122+
name: str, input, id_dict, output=None, key=None, as_text_output=None
123+
) -> None:
122124
if output is None:
123125
output = input
124126
# First, check without semicolon
@@ -136,8 +138,8 @@ def check(name, input, id_dict, output=None, key=None, as_text_output=None):
136138

137139

138140
def test_domain_c_ast_expressions() -> None:
139-
def expr_check(expr, output=None):
140-
parser = DefinitionParser(expr, location=None, config=Config())
141+
def expr_check(expr: str, output: str | None = None) -> None:
142+
parser = DefinitionParser(expr, location=None, config=Config()) # type: ignore[arg-type]
141143
parser.allowFallbackExpressionParsing = False
142144
ast = parser.parse_expression()
143145
parser.assert_end()
@@ -337,8 +339,8 @@ def expr_check(expr, output=None):
337339

338340

339341
def test_domain_c_ast_fundamental_types() -> None:
340-
def types():
341-
def signed(t):
342+
def types() -> Generator[str]:
343+
def signed(t: str) -> Generator[str]:
342344
yield t
343345
yield 'signed ' + t
344346
yield 'unsigned ' + t

tests/test_domains/test_domain_cpp.py

Lines changed: 27 additions & 17 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,13 @@ def _check(name, input, id_dict, output, key, as_text_output):
105107
except NoOldIdError:
106108
id_actual.append(None)
107109

108-
res = [True]
109-
for i in range(1, _max_id + 1):
110-
res.append(id_expected[i] == id_actual[i])
110+
res_bools = [True]
111+
res_bools.extend(id_expected[i] == id_actual[i] for i in range(1, _max_id + 1))
111112

112-
if not all(res):
113+
if not all(res_bools):
113114
print('input: %s' % input.rjust(20))
114115
for i in range(1, _max_id + 1):
115-
if res[i]:
116+
if res_bools[i]:
116117
continue
117118
print('Error in id version %d.' % i)
118119
print('result: %s' % id_actual[i])
@@ -121,7 +122,14 @@ def _check(name, input, id_dict, output, key, as_text_output):
121122
raise DefinitionError
122123

123124

124-
def check(name, input, id_dict, output=None, key=None, as_text_output=None):
125+
def check(
126+
name: str,
127+
input: str,
128+
id_dict: dict[int, str],
129+
output=None,
130+
key=None,
131+
as_text_output=None,
132+
) -> None:
125133
if output is None:
126134
output = input
127135
# First, check without semicolon
@@ -177,7 +185,7 @@ def make_id_v2():
177185

178186

179187
def test_domain_cpp_ast_expressions() -> None:
180-
def expr_check(expr, id, id4=None):
188+
def expr_check(expr: str, id: str, id4: str | None = None):
181189
ids = 'IE1CIA%s_1aE'
182190
# call .format() on the expr to unescape double curly braces
183191
id_dict = {2: ids % expr.format(), 3: ids % id}
@@ -189,7 +197,7 @@ class Config:
189197
cpp_id_attributes = ['id_attr']
190198
cpp_paren_attributes = ['paren_attr']
191199

192-
parser = DefinitionParser(expr, location=None, config=Config())
200+
parser = DefinitionParser(expr, location=None, config=Config()) # type: ignore[arg-type]
193201
parser.allowFallbackExpressionParsing = False
194202
ast = parser.parse_expression()
195203
res = str(ast)
@@ -1472,12 +1480,12 @@ def test_domain_cpp_ast_attributes() -> None:
14721480
check('enumerator', '{key}Foo [[attr1]] [[attr2]] = 42', {2: '3Foo'})
14731481

14741482

1475-
def check_ast_xref_parsing(target):
1483+
def check_ast_xref_parsing(target: str) -> None:
14761484
class Config:
14771485
cpp_id_attributes = ['id_attr']
14781486
cpp_paren_attributes = ['paren_attr']
14791487

1480-
parser = DefinitionParser(target, location='', config=Config())
1488+
parser = DefinitionParser(target, location='', config=Config()) # type: ignore[arg-type]
14811489
parser.parse_xref_object()
14821490
parser.assert_end()
14831491

@@ -1518,6 +1526,8 @@ def test_domain_cpp_ast_xref_parsing() -> None:
15181526
def test_domain_cpp_template_parameters_is_pack(param: str, is_pack: bool):
15191527
def parse_template_parameter(param: str):
15201528
ast = parse('type', 'template<' + param + '> X')
1529+
assert ast.templatePrefix is not None
1530+
assert ast.templatePrefix.templates is not None
15211531
return ast.templatePrefix.templates[0].params[0]
15221532

15231533
ast = parse_template_parameter(param)

tests/test_extensions/test_ext_intersphinx.py

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

5353

54-
def fake_node(domain, type, target, content, **attrs):
54+
def fake_node(
55+
domain: str, type: str, target: str, content: str, **attrs
56+
) -> tuple[addnodes.pending_xref, nodes.emphasis]:
5557
contnode = nodes.emphasis(content, content)
5658
node = addnodes.pending_xref('')
5759
node['reftarget'] = target
@@ -62,12 +64,14 @@ def fake_node(domain, type, target, content, **attrs):
6264
return node, contnode
6365

6466

65-
def reference_check(app, *args, **kwds):
67+
def reference_check(app: SphinxTestApp, *args, **kwds):
6668
node, contnode = fake_node(*args, **kwds)
6769
return missing_reference(app, app.env, node, contnode)
6870

6971

70-
def set_config(app, mapping):
72+
def set_config(
73+
app: SphinxTestApp, mapping: dict[str, tuple[str, str | list[str]]]
74+
) -> None:
7175
# copy *mapping* so that normalization does not alter it
7276
app.config.intersphinx_mapping = mapping.copy()
7377
app.config.intersphinx_cache_limit = 0
@@ -544,7 +548,7 @@ def test_validate_intersphinx_mapping_warnings(app: SphinxTestApp) -> None:
544548
'good-target-1': ('e.example', None), # valid inventory location (None)
545549
'good-target-2': ('f.example', ('x',)), # valid inventory location (sequence input)
546550
} # fmt: skip
547-
set_config(app, bad_intersphinx_mapping)
551+
set_config(app, bad_intersphinx_mapping) # type: ignore[arg-type]
548552

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

tests/test_util/test_util_inspect.py

Lines changed: 9 additions & 6 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}
@@ -985,8 +988,8 @@ def my_method(self):
985988
assert not inspect.is_builtin_class_method(MyInt, 'does_not_exist')
986989
assert not inspect.is_builtin_class_method(4, 'still does not crash')
987990

988-
class ObjectWithMroAttr:
989-
def __init__(self, mro_attr):
991+
class ObjectWithMroAttr: # noqa: B903
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)