Typecheck main
Always have tasks_list be a list, not potentially some fancier iterable.
Bypass mypy's somewhat legitimate complaint about REFERENCE and DRIVER in
task_class: they could potentially be instance attributes, but we rely on
them being class attributes. Python does normally guarantee their existence
as class attributes (unless a derived class explicitly deletes them), but
they could be overridden by an instance attribute; that's just something
we don't do, so the class attribute's value is legitimate. We can't
expect mypy to know that, so work around its complaint.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/scripts/analyze_outcomes.py b/tests/scripts/analyze_outcomes.py
index 9f8c2c3..f681a30 100755
--- a/tests/scripts/analyze_outcomes.py
+++ b/tests/scripts/analyze_outcomes.py
@@ -761,8 +761,7 @@
'analyze_block_cipher_dispatch': DriverVSReference_block_cipher_dispatch,
}
-
-def main():
+def main() -> None:
main_results = Results()
try:
@@ -789,7 +788,7 @@
sys.exit(0)
if options.specified_tasks == 'all':
- tasks_list = KNOWN_TASKS.keys()
+ tasks_list = list(KNOWN_TASKS.keys())
else:
tasks_list = re.split(r'[, ]+', options.specified_tasks)
for task_name in tasks_list:
@@ -810,9 +809,16 @@
if not issubclass(task_class, DriverVSReference):
sys.stderr.write("please provide valid outcomes file for {}.\n".format(task_name))
sys.exit(2)
+ # mypy isn't smart enough to know that REFERENCE and DRIVER
+ # are *class* attributes of all classes derived from
+ # DriverVSReference. (It would be smart enough if we had an
+ # instance of task_class, but we can't construct an instance
+ # until we have the outcome data, so at this point we only
+ # have the class.) So we use indirection to access the class
+ # attributes.
execute_reference_driver_tests(main_results,
- task_class.REFERENCE,
- task_class.DRIVER,
+ getattr(task_class, 'REFERENCE'),
+ getattr(task_class, 'DRIVER'),
options.outcomes)
outcomes = read_outcome_file(options.outcomes)