Skip to content
This repository was archived by the owner on Feb 10, 2026. It is now read-only.

Commit b865acb

Browse files
committed
tests: fix remaining type errors
1 parent 663df7e commit b865acb

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

tests/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class Test(object):
1313

14-
STAGES: dict = {
14+
STAGES: dict[str, list[str]] = {
1515
"autogen": ["autogen.sh"],
1616
"configure": ["configure.sh"],
1717
"make": ["make.sh", "cmake.sh"],
@@ -39,12 +39,14 @@ def print_log_tail_on_fail(script_path):
3939
if os.path.isfile(logfile):
4040
grep_cmd = ['grep', '-i', '-A', '20', '-E', 'panicked|error', logfile]
4141
grep = subprocess.Popen(grep_cmd, stdout=subprocess.PIPE)
42+
assert grep.stdout is not None
4243
for line in grep.stdout:
4344
print(line.decode().rstrip())
4445

4546
# fall back to tail if grep didn't find anything
4647
if grep.returncode != 0:
4748
tail = subprocess.Popen(['tail', '-n', '20', logfile], stdout=subprocess.PIPE)
49+
assert tail.stdout is not None
4850
for line in tail.stdout:
4951
print(line.decode().rstrip())
5052
else:
@@ -81,6 +83,8 @@ def print_log_tail_on_fail(script_path):
8183
nc=Colors.NO_COLOR,
8284
stage=stage,
8385
script=relpath)
86+
else:
87+
line = ""
8488

8589
# if we already have `compile_commands.json`, skip the build stages
8690
if stage in ["autogen", "configure", "make"]:
@@ -181,7 +185,7 @@ def run(self, conf: Config) -> bool:
181185
self.ensure_submodule_checkout()
182186

183187
stages = Test.STAGES.keys()
184-
if conf.stages:
188+
if conf.stages is not None:
185189
# Check that all stages are valid
186190
for stage in conf.stages:
187191
if stage not in Test.STAGES:

tests/util.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import json
55
import errno
66

7-
from typing import List, Iterable
7+
from typing import Any, List, Iterable, Never, Sequence
88

99
CONF_YML: str = "conf.yml"
1010

1111

1212
class Config(object):
13+
stages: list[str] | None
14+
1315
def __init__(self, args):
1416
self.verbose = args.verbose
1517
self.projects = args.projects # projects filter
@@ -18,8 +20,8 @@ def __init__(self, args):
1820
self.project_dirs = find_project_dirs(self)
1921
self.project_conf = {cf: get_yaml(cf) for cf in get_conf_files(self)}
2022

21-
def try_get_conf_for(self, conf_file, *keys: List[str]):
22-
def lookup(yaml, keys: List[str]):
23+
def try_get_conf_for(self, conf_file, *keys: str):
24+
def lookup(yaml, keys: Sequence[str]):
2325
if not keys:
2426
return None
2527
head, *tail = keys
@@ -44,7 +46,7 @@ class Colors(object):
4446
NO_COLOR = '\033[0m'
4547

4648

47-
def die(emsg: str, status: int=errno.EINVAL):
49+
def die(emsg: str, status: int=errno.EINVAL) -> Never:
4850
(red, nc) = (Colors.FAIL, Colors.NO_COLOR)
4951
print(f"{red}error:{nc} {emsg}", file=sys.stderr)
5052
exit(status)
@@ -97,15 +99,15 @@ def find_project_dirs(conf: Config) -> List[str]:
9799
return [os.path.join(script_dir, s) for s in subdirs]
98100

99101

100-
def get_yaml(file: str) -> dict:
102+
def get_yaml(file: str) -> dict[str, Any]:
101103
with open(file, 'r') as stream:
102104
try:
103105
return yaml.safe_load(stream)
104106
except yaml.YAMLError as exc:
105107
die(str(exc))
106108

107109

108-
def check_compile_commands(compile_commands_path: str) -> (bool, str):
110+
def check_compile_commands(compile_commands_path: str) -> tuple[bool, str]:
109111
"""
110112
Return True iff compile_commands_path points to a valid
111113
compile_commands.json and all referenced source files exist.

0 commit comments

Comments
 (0)