1- # command_util.py
2-
3- import subprocess
4- import logging
5- from returns .maybe import Maybe
6- from errors import CommandError
7- from pathlib import Path
1+ # fuzz/command_util.py
82
93import subprocess
104import time
115import logging
126from pathlib import Path
7+ from typing import Optional
138from returns .maybe import Maybe
149from errors import CommandError
1510
11+
1612def _run_subprocess (
1713 cmd : str ,
18- cwd : Path = None ,
14+ cwd : Optional [ Path ] = None ,
1915 capture_output : bool = False ,
20- timeout : int = None ,
21- logger : logging .Logger = None ,
16+ timeout : Optional [ int ] = None ,
17+ logger : Optional [ logging .Logger ] = None ,
2218) -> tuple [int , list [str ]]:
2319 """
2420 低层执行子进程命令
@@ -43,6 +39,7 @@ def _run_subprocess(
4339
4440 try :
4541 if capture_output :
42+ assert process .stdout is not None # ✅ MyPy static check
4643 while True :
4744 line = process .stdout .readline ()
4845 if line :
@@ -79,7 +76,7 @@ def run_command_build_fuzz(
7976 cmd : str ,
8077 oss_fuzz_dir : Path ,
8178 project : str = "" ,
82- allowed_exit_codes : Maybe [list [int ]] = Maybe .empty ,
79+ allowed_exit_codes : Maybe [list [int ]] = Maybe .empty () ,
8380 skip_yes : bool = False
8481) -> int :
8582 """build_fuzz.py 中使用的 run_command,简化版,抛异常"""
@@ -98,7 +95,7 @@ def run_command_fuzz_all_targets(
9895 cmd : str ,
9996 log_msg : str ,
10097 logger : logging .Logger ,
101- allowed_exit_codes : Maybe [list [int ]] = Maybe .empty ,
98+ allowed_exit_codes : Maybe [list [int ]] = Maybe .empty () ,
10299 timeout : int = 3600 ,
103100) -> bool :
104101 """run_fuzz_all_targets_print1.py 中使用,带实时日志与超时,返回bool"""
@@ -111,4 +108,3 @@ def run_command_fuzz_all_targets(
111108 logger .error (f"❌ Command execution failed, exit code: { exit_code } " )
112109 return False
113110 return True
114-
0 commit comments