Skip to content

Commit 8d7a8bc

Browse files
committed
Tighten type annotations to remove str-based commands
1 parent dc17b91 commit 8d7a8bc

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pytensor/link/c/cmodule.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ def compile_args(march_flags=True):
21052105
)
21062106
detect_march = False
21072107

2108-
def get_lines(cmd: list[str] | str, parse: bool = True) -> list[str] | None:
2108+
def get_lines(cmd: list[str], parse: bool = True) -> list[str] | None:
21092109
p = subprocess_Popen(
21102110
cmd,
21112111
stdout=subprocess.PIPE,

pytensor/utils.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def maybe_add_to_os_environ_pathlist(var: str, newpath: Path | str) -> None:
123123
pass
124124

125125

126-
def subprocess_Popen(command: str | list[str], **params):
126+
def subprocess_Popen(command: list[str], **params) -> subprocess.Popen:
127127
"""
128128
Utility function to work around windows behavior that open windows.
129129
@@ -142,12 +142,12 @@ def subprocess_Popen(command: str | list[str], **params):
142142
# in "The filename, directory name, or volume label syntax is incorrect" error message.
143143
# Passing the command as a single string solves this problem.
144144
if isinstance(command, list):
145-
command = " ".join(command)
145+
command = " ".join(command) # type: ignore[assignment]
146146

147147
return subprocess.Popen(command, startupinfo=startupinfo, **params)
148148

149149

150-
def call_subprocess_Popen(command, **params):
150+
def call_subprocess_Popen(command: list[str], **params) -> int:
151151
"""
152152
Calls subprocess_Popen and discards the output, returning only the
153153
exit code.
@@ -165,13 +165,17 @@ def call_subprocess_Popen(command, **params):
165165
return returncode
166166

167167

168-
def output_subprocess_Popen(command, **params):
168+
def output_subprocess_Popen(command: list[str], **params) -> tuple[bytes, bytes, int]:
169169
"""
170170
Calls subprocess_Popen, returning the output, error and exit code
171171
in a tuple.
172172
"""
173173
if "stdout" in params or "stderr" in params:
174174
raise TypeError("don't use stderr or stdout with output_subprocess_Popen")
175+
if "encoding" in params:
176+
raise TypeError(
177+
"adjust the output_subprocess_Popen type annotation to support str"
178+
)
175179
params["stdout"] = subprocess.PIPE
176180
params["stderr"] = subprocess.PIPE
177181
p = subprocess_Popen(command, **params)

0 commit comments

Comments
 (0)