2121from .runtests import RunTests , JsonFile , JsonFileType
2222from .single import PROGRESS_MIN_TIME
2323from .utils import (
24- StrPath , StrJSON , TestName , MS_WINDOWS ,
24+ StrPath , TestName , MS_WINDOWS ,
2525 format_duration , print_warning , count , plural )
2626from .worker import create_worker_process , USE_PROCESS_GROUP
2727
@@ -104,9 +104,9 @@ def __init__(self, worker_id: int, runner: "RunWorkers") -> None:
104104 self .output = runner .output
105105 self .timeout = runner .worker_timeout
106106 self .log = runner .log
107- self .test_name = None
108- self .start_time = None
109- self ._popen = None
107+ self .test_name : TestName | None = None
108+ self .start_time : float | None = None
109+ self ._popen : subprocess . Popen [ str ] | None = None
110110 self ._killed = False
111111 self ._stopped = False
112112
@@ -160,7 +160,7 @@ def stop(self) -> None:
160160 self ._kill ()
161161
162162 def _run_process (self , runtests : RunTests , output_fd : int ,
163- tmp_dir : StrPath | None = None ) -> int :
163+ tmp_dir : StrPath | None = None ) -> int | None :
164164 popen = create_worker_process (runtests , output_fd , tmp_dir )
165165 self ._popen = popen
166166 self ._killed = False
@@ -260,7 +260,7 @@ def create_worker_runtests(self, test_name: TestName, json_file: JsonFile) -> Ru
260260 ** kwargs )
261261
262262 def run_tmp_files (self , worker_runtests : RunTests ,
263- stdout_fd : int ) -> ( int , list [StrPath ]) :
263+ stdout_fd : int ) -> tuple [ int | None , list [StrPath ]] :
264264 # gh-93353: Check for leaked temporary files in the parent process,
265265 # since the deletion of temporary files can happen late during
266266 # Python finalization: too late for libregrtest.
@@ -297,13 +297,13 @@ def read_json(self, json_file: JsonFile, json_tmpfile: TextIO | None,
297297 try :
298298 if json_tmpfile is not None :
299299 json_tmpfile .seek (0 )
300- worker_json : StrJSON = json_tmpfile .read ()
300+ worker_json = json_tmpfile .read ()
301301 elif json_file .file_type == JsonFileType .STDOUT :
302302 stdout , _ , worker_json = stdout .rpartition ("\n " )
303303 stdout = stdout .rstrip ()
304304 else :
305305 with json_file .open (encoding = 'utf8' ) as json_fp :
306- worker_json : StrJSON = json_fp .read ()
306+ worker_json = json_fp .read ()
307307 except Exception as exc :
308308 # gh-101634: Catch UnicodeDecodeError if stdout cannot be
309309 # decoded from encoding
@@ -414,8 +414,8 @@ def wait_stopped(self, start_time: float) -> None:
414414 break
415415
416416
417- def get_running (workers : list [WorkerThread ]) -> list [ str ] :
418- running = []
417+ def get_running (workers : list [WorkerThread ]) -> str | None :
418+ running : list [ str ] = []
419419 for worker in workers :
420420 test_name = worker .test_name
421421 if not test_name :
@@ -431,7 +431,7 @@ def get_running(workers: list[WorkerThread]) -> list[str]:
431431
432432class RunWorkers :
433433 def __init__ (self , num_workers : int , runtests : RunTests ,
434- logger : Logger , results : TestResult ) -> None :
434+ logger : Logger , results : TestResults ) -> None :
435435 self .num_workers = num_workers
436436 self .runtests = runtests
437437 self .log = logger .log
@@ -446,10 +446,10 @@ def __init__(self, num_workers: int, runtests: RunTests,
446446 # Rely on faulthandler to kill a worker process. This timouet is
447447 # when faulthandler fails to kill a worker process. Give a maximum
448448 # of 5 minutes to faulthandler to kill the worker.
449- self .worker_timeout = min (self .timeout * 1.5 , self .timeout + 5 * 60 )
449+ self .worker_timeout : float | None = min (self .timeout * 1.5 , self .timeout + 5 * 60 )
450450 else :
451451 self .worker_timeout = None
452- self .workers = None
452+ self .workers : list [ WorkerThread ] | None = None
453453
454454 jobs = self .runtests .get_jobs ()
455455 if jobs is not None :
@@ -529,7 +529,7 @@ def display_result(self, mp_result: MultiprocessResult) -> None:
529529 text += f' -- { running } '
530530 self .display_progress (self .test_index , text )
531531
532- def _process_result (self , item : QueueOutput ) -> bool :
532+ def _process_result (self , item : QueueOutput ) -> TestResult :
533533 """Returns True if test runner must stop."""
534534 if item [0 ]:
535535 # Thread got an exception
0 commit comments