Skip to content

Commit 7d81c27

Browse files
authored
Update open process types (#3076)
1 parent a0cc5a1 commit 7d81c27

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

newsfragments/3076.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update ``trio.lowlevel.open_process``'s documentation to allow bytes.

src/trio/_subprocess.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def kill(self) -> None:
304304

305305

306306
async def _open_process(
307-
command: list[str] | str,
307+
command: StrOrBytesPath | Sequence[StrOrBytesPath],
308308
*,
309309
stdin: int | HasFileno | None = None,
310310
stdout: int | HasFileno | None = None,
@@ -329,13 +329,14 @@ async def _open_process(
329329
want.
330330
331331
Args:
332-
command (list or str): The command to run. Typically this is a
333-
sequence of strings such as ``['ls', '-l', 'directory with spaces']``,
334-
where the first element names the executable to invoke and the other
335-
elements specify its arguments. With ``shell=True`` in the
336-
``**options``, or on Windows, ``command`` may alternatively
337-
be a string, which will be parsed following platform-dependent
338-
:ref:`quoting rules <subprocess-quoting>`.
332+
command: The command to run. Typically this is a sequence of strings or
333+
bytes such as ``['ls', '-l', 'directory with spaces']``, where the
334+
first element names the executable to invoke and the other elements
335+
specify its arguments. With ``shell=True`` in the ``**options``, or on
336+
Windows, ``command`` can be a string or bytes, which will be parsed
337+
following platform-dependent :ref:`quoting rules
338+
<subprocess-quoting>`. In all cases ``command`` can be a path or a
339+
sequence of paths.
339340
stdin: Specifies what the child process's standard input
340341
stream should connect to: output written by the parent
341342
(``subprocess.PIPE``), nothing (``subprocess.DEVNULL``),
@@ -369,15 +370,16 @@ async def _open_process(
369370
)
370371

371372
if os.name == "posix":
372-
if isinstance(command, str) and not options.get("shell"):
373+
# TODO: how do paths and sequences thereof play with `shell=True`?
374+
if isinstance(command, (str, bytes)) and not options.get("shell"):
373375
raise TypeError(
374-
"command must be a sequence (not a string) if shell=False "
375-
"on UNIX systems",
376+
"command must be a sequence (not a string or bytes) if "
377+
"shell=False on UNIX systems",
376378
)
377-
if not isinstance(command, str) and options.get("shell"):
379+
if not isinstance(command, (str, bytes)) and options.get("shell"):
378380
raise TypeError(
379-
"command must be a string (not a sequence) if shell=True "
380-
"on UNIX systems",
381+
"command must be a string or bytes (not a sequence) if "
382+
"shell=True on UNIX systems",
381383
)
382384

383385
trio_stdin: ClosableSendStream | None = None

src/trio/_tools/gen_exports.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def process(files: Iterable[File], *, do_test: bool) -> None:
303303
print("Generated sources are up to date.")
304304
else:
305305
for new_path, new_source in new_files.items():
306-
with open(new_path, "w", encoding="utf-8") as f:
306+
with open(new_path, "w", encoding="utf-8", newline="\n") as f:
307307
f.write(new_source)
308308
print("Regenerated sources successfully.")
309309
if not matches_disk:

0 commit comments

Comments
 (0)