Skip to content

Commit

Permalink
Update open process types (#3076)
Browse files Browse the repository at this point in the history
  • Loading branch information
A5rocks committed Sep 18, 2024
1 parent a0cc5a1 commit 7d81c27
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions newsfragments/3076.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update ``trio.lowlevel.open_process``'s documentation to allow bytes.
30 changes: 16 additions & 14 deletions src/trio/_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def kill(self) -> None:


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

if os.name == "posix":
if isinstance(command, str) and not options.get("shell"):
# TODO: how do paths and sequences thereof play with `shell=True`?
if isinstance(command, (str, bytes)) and not options.get("shell"):
raise TypeError(
"command must be a sequence (not a string) if shell=False "
"on UNIX systems",
"command must be a sequence (not a string or bytes) if "
"shell=False on UNIX systems",
)
if not isinstance(command, str) and options.get("shell"):
if not isinstance(command, (str, bytes)) and options.get("shell"):
raise TypeError(
"command must be a string (not a sequence) if shell=True "
"on UNIX systems",
"command must be a string or bytes (not a sequence) if "
"shell=True on UNIX systems",
)

trio_stdin: ClosableSendStream | None = None
Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tools/gen_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def process(files: Iterable[File], *, do_test: bool) -> None:
print("Generated sources are up to date.")
else:
for new_path, new_source in new_files.items():
with open(new_path, "w", encoding="utf-8") as f:
with open(new_path, "w", encoding="utf-8", newline="\n") as f:
f.write(new_source)
print("Regenerated sources successfully.")
if not matches_disk:
Expand Down

0 comments on commit 7d81c27

Please sign in to comment.