Skip to content

Commit 368c0e4

Browse files
committed
mytype
1 parent 5e28b5c commit 368c0e4

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

fuzz/command_util.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import time
55
import logging
66
from pathlib import Path
7-
from typing import Optional
7+
from typing import Optional, cast
88
from returns.maybe import Maybe
99
from errors import CommandError
1010

11-
1211
def _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

0 commit comments

Comments
 (0)