File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import time
55import logging
66from pathlib import Path
7- from typing import Optional
7+ from typing import Optional , cast
88from returns .maybe import Maybe
99from errors import CommandError
1010
11-
1211def _run_subprocess (
1312 cmd : str ,
1413 cwd : Optional [Path ] = None ,
@@ -39,17 +38,21 @@ def _run_subprocess(
3938
4039 try :
4140 if capture_output :
42- assert process .stdout is not None # ✅ MyPy static check
41+ # 类型断言确保 stdout 不为 None
42+ stdout = cast (Optional [subprocess .PIPE ], process .stdout )
43+ if stdout is None :
44+ raise RuntimeError ("Stdout should not be None when capture_output is True" )
45+
4346 while True :
44- line = process . stdout .readline ()
47+ line = stdout .readline ()
4548 if line :
4649 output_lines .append (line .rstrip ())
4750 if logger :
4851 logger .debug (line .rstrip ())
4952 elif process .poll () is not None :
5053 break
5154
52- if timeout and (time .time () - start_time ) > timeout :
55+ if timeout is not None and (time .time () - start_time ) > timeout :
5356 if logger :
5457 logger .error (f"⌛ Command timed out after { timeout } seconds" )
5558 process .terminate ()
@@ -107,4 +110,4 @@ def run_command_fuzz_all_targets(
107110 if exit_code not in [0 , * allowed_codes ]:
108111 logger .error (f"❌ Command execution failed, exit code: { exit_code } " )
109112 return False
110- return True
113+ return True
You can’t perform that action at this time.
0 commit comments