Skip to content

Commit 0ca1803

Browse files
committed
chore(types): type functions in tests
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 1faa32e commit 0ca1803

15 files changed

+74
-65
lines changed

bin/make_dependency_update_pr.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ def shell(cmd, *, check: bool, **kwargs):
1616
return run([cmd], shell=True, check=check, **kwargs)
1717

1818

19-
def git_repo_has_changes():
20-
unstaged_changes = shell("git diff-index --quiet HEAD --", check=False).returncode != 0
21-
staged_changes = shell("git diff-index --quiet --cached HEAD --", check=False).returncode != 0
19+
def git_repo_has_changes() -> bool:
20+
unstaged_changes: bool = shell("git diff-index --quiet HEAD --", check=False).returncode != 0
21+
staged_changes: bool = (
22+
shell("git diff-index --quiet --cached HEAD --", check=False).returncode != 0
23+
)
2224
return unstaged_changes or staged_changes
2325

2426

2527
@click.command()
26-
def main():
28+
def main() -> None:
2729
project_root = Path(__file__).parent / ".."
2830
os.chdir(project_root)
2931

bin/run_example_ci_configs.py

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

55
import os
66
import shutil
7+
import subprocess
78
import sys
89
import textwrap
910
import time
1011
import typing
1112
from glob import glob
1213
from pathlib import Path
13-
from subprocess import run
1414
from urllib.parse import quote
1515

1616
import click
1717

1818

19-
def shell(cmd, *, check: bool, **kwargs):
20-
return run([cmd], shell=True, check=check, **kwargs)
19+
def shell(cmd: str, *, check: bool, **kwargs: object) -> subprocess.CompletedProcess[str]:
20+
return subprocess.run([cmd], shell=True, check=check, **kwargs) # type: ignore[call-overload, no-any-return]
2121

2222

23-
def git_repo_has_changes():
23+
def git_repo_has_changes() -> bool:
2424
unstaged_changes = shell("git diff-index --quiet HEAD --", check=False).returncode != 0
2525
staged_changes = shell("git diff-index --quiet --cached HEAD --", check=False).returncode != 0
2626
return unstaged_changes or staged_changes
2727

2828

29-
def generate_basic_project(path):
29+
def generate_basic_project(path: Path) -> None:
3030
sys.path.insert(0, "")
3131
from test.test_projects.c import new_c_project
3232

@@ -79,7 +79,7 @@ class CIService(typing.NamedTuple):
7979
]
8080

8181

82-
def ci_service_for_config_file(config_file):
82+
def ci_service_for_config_file(config_file: str) -> CIService:
8383
filename = Path(config_file).name
8484

8585
try:
@@ -134,7 +134,7 @@ def run_example_ci_configs(config_files=None):
134134
dst_config_file.parent.mkdir(parents=True, exist_ok=True)
135135
shutil.copyfile(src_config_file, dst_config_file)
136136

137-
run(["git", "add", example_project], check=True)
137+
subprocess.run(["git", "add", example_project], check=True)
138138
message = textwrap.dedent(
139139
f"""\
140140
Test example minimal configs
@@ -144,7 +144,7 @@ def run_example_ci_configs(config_files=None):
144144
Time: {timestamp}
145145
"""
146146
)
147-
run(["git", "commit", "--no-verify", "--message", message], check=True)
147+
subprocess.run(["git", "commit", "--no-verify", "--message", message], check=True)
148148
shell(f"git subtree --prefix={example_project} push origin {branch_name}", check=True)
149149

150150
print("---")

bin/update_how_it_works_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
)
1919

2020

21-
def main():
21+
def main() -> None:
2222
subprocess.run(["mkdocs", "build"], check=True)
2323

2424
hti = Html2Image(custom_flags=["--force-device-scale-factor=2"])

bin/update_readme_changelog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121

2222

23-
def main():
23+
def main() -> None:
2424
changelog_text = CHANGELOG_FILE.read_text()
2525
readme_text = README_FILE.read_text()
2626

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ warn_unused_configs = true
115115

116116
strict = true
117117
disallow_untyped_defs = false
118-
disallow_untyped_calls = false
119118
disallow_incomplete_defs = false
120119

121120
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
@@ -124,9 +123,7 @@ warn_unreachable = false
124123
[[tool.mypy.overrides]]
125124
module = "cibuildwheel.*"
126125
disallow_untyped_defs = true
127-
disallow_untyped_calls = true
128126
disallow_incomplete_defs = true
129-
disallow_untyped_decorators = true
130127

131128
[[tool.mypy.overrides]]
132129
module = [

test/test_dependency_versions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import platform
44
import re
55
import textwrap
6+
from pathlib import Path
67

78
import pytest
89

@@ -46,8 +47,8 @@
4647
VERSION_REGEX = r"([\w-]+)==([^\s]+)"
4748

4849

49-
def get_versions_from_constraint_file(constraint_file):
50-
constraint_file_text = constraint_file.read_text(encoding="utf8")
50+
def get_versions_from_constraint_file(constraint_file: Path) -> dict[str, str]:
51+
constraint_file_text = constraint_file.read_text(encoding="utf-8")
5152

5253
return dict(re.findall(VERSION_REGEX, constraint_file_text))
5354

test/test_from_sdist.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
import sys
66
import textwrap
7+
from collections.abc import Mapping
78
from pathlib import Path
89
from tempfile import TemporaryDirectory
910

@@ -28,7 +29,11 @@ def make_sdist(project: TestProject, working_dir: Path) -> Path:
2829
return next(sdist_dir.glob("*.tar.gz"))
2930

3031

31-
def cibuildwheel_from_sdist_run(sdist_path, add_env=None, config_file=None):
32+
def cibuildwheel_from_sdist_run(
33+
sdist_path: Path | str,
34+
add_env: Mapping[str, str] | None = None,
35+
config_file: str | None = None,
36+
) -> list[str]:
3237
env = os.environ.copy()
3338

3439
if add_env:

test/test_projects/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pathlib import Path
99

1010

11-
def main():
11+
def main() -> None:
1212
parser = ArgumentParser(
1313
prog="python -m test.test_projects", description="Generate a test project to check it out"
1414
)

test/test_projects/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class TestProject:
2222
files: FilesDict
2323
template_context: TemplateContext
2424

25-
def __init__(self):
25+
def __init__(self) -> None:
2626
self.files = {}
2727
self.template_context = {}
2828

29-
def generate(self, path: Path):
29+
def generate(self, path: Path) -> None:
3030
for filename, content in self.files.items():
3131
file_path = path / filename
3232
file_path.parent.mkdir(parents=True, exist_ok=True)
@@ -37,7 +37,7 @@ def generate(self, path: Path):
3737

3838
f.write(content)
3939

40-
def copy(self):
40+
def copy(self) -> TestProject:
4141
other = TestProject()
4242
other.files = self.files.copy()
4343
other.template_context = self.template_context.copy()

test/test_projects/c.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@
7878

7979
def new_c_project(
8080
*,
81-
spam_c_top_level_add="",
82-
spam_c_function_add="",
83-
setup_py_add="",
84-
setup_py_extension_args_add="",
85-
setup_py_setup_args_add="",
86-
setup_cfg_add="",
87-
):
81+
spam_c_top_level_add: str = "",
82+
spam_c_function_add: str = "",
83+
setup_py_add: str = "",
84+
setup_py_extension_args_add: str = "",
85+
setup_py_setup_args_add: str = "",
86+
setup_cfg_add: str = "",
87+
) -> TestProject:
8888
project = TestProject()
8989

9090
project.files.update(

0 commit comments

Comments
 (0)