提交 c7c33fbc authored 作者: Ben Mares's avatar Ben Mares 提交者: Michael Osthege

Tighten type annotations to remove str-based commands

上级 080214a3
...@@ -2105,7 +2105,7 @@ class GCC_compiler(Compiler): ...@@ -2105,7 +2105,7 @@ class GCC_compiler(Compiler):
) )
detect_march = False detect_march = False
def get_lines(cmd: list[str] | str, parse: bool = True) -> list[str] | None: def get_lines(cmd: list[str], parse: bool = True) -> list[str] | None:
p = subprocess_Popen( p = subprocess_Popen(
cmd, cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
......
...@@ -123,7 +123,7 @@ def maybe_add_to_os_environ_pathlist(var: str, newpath: Path | str) -> None: ...@@ -123,7 +123,7 @@ def maybe_add_to_os_environ_pathlist(var: str, newpath: Path | str) -> None:
pass pass
def subprocess_Popen(command: str | list[str], **params): def subprocess_Popen(command: list[str], **params) -> subprocess.Popen:
""" """
Utility function to work around windows behavior that open windows. Utility function to work around windows behavior that open windows.
...@@ -142,12 +142,12 @@ def subprocess_Popen(command: str | list[str], **params): ...@@ -142,12 +142,12 @@ def subprocess_Popen(command: str | list[str], **params):
# in "The filename, directory name, or volume label syntax is incorrect" error message. # in "The filename, directory name, or volume label syntax is incorrect" error message.
# Passing the command as a single string solves this problem. # Passing the command as a single string solves this problem.
if isinstance(command, list): if isinstance(command, list):
command = " ".join(command) command = " ".join(command) # type: ignore[assignment]
return subprocess.Popen(command, startupinfo=startupinfo, **params) return subprocess.Popen(command, startupinfo=startupinfo, **params)
def call_subprocess_Popen(command, **params): def call_subprocess_Popen(command: list[str], **params) -> int:
""" """
Calls subprocess_Popen and discards the output, returning only the Calls subprocess_Popen and discards the output, returning only the
exit code. exit code.
...@@ -165,13 +165,17 @@ def call_subprocess_Popen(command, **params): ...@@ -165,13 +165,17 @@ def call_subprocess_Popen(command, **params):
return returncode return returncode
def output_subprocess_Popen(command, **params): def output_subprocess_Popen(command: list[str], **params) -> tuple[bytes, bytes, int]:
""" """
Calls subprocess_Popen, returning the output, error and exit code Calls subprocess_Popen, returning the output, error and exit code
in a tuple. in a tuple.
""" """
if "stdout" in params or "stderr" in params: if "stdout" in params or "stderr" in params:
raise TypeError("don't use stderr or stdout with output_subprocess_Popen") raise TypeError("don't use stderr or stdout with output_subprocess_Popen")
if "encoding" in params:
raise TypeError(
"adjust the output_subprocess_Popen type annotation to support str"
)
params["stdout"] = subprocess.PIPE params["stdout"] = subprocess.PIPE
params["stderr"] = subprocess.PIPE params["stderr"] = subprocess.PIPE
p = subprocess_Popen(command, **params) p = subprocess_Popen(command, **params)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论