Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update open process types #3076

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
28 changes: 14 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],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering, why is type var here called StrOrBytesPath? Wouldn't it be StrOrBytes, or is StrOrBytesPath special somehow?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's typed as str | bytes | PathLike[str] | PathLike[bytes]?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the docstring currently in place, I wasn't under the impression it supported pathlikes. If you could update that then, that would be great!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring atm distinguishes what is possible with shell=True and what isn't, but I think paths are fine either way. I can update the docstring though. (this also appears in the function signature Sphinx makes)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would seem to be for the best to mention that, yes. After that, I have no objections.

*,
stdin: int | HasFileno | None = None,
stdout: int | HasFileno | None = None,
Expand All @@ -329,13 +329,13 @@ 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 (str or bytes or Sequence[str] or Sequence[bytes]): The command to
A5rocks marked this conversation as resolved.
Show resolved Hide resolved
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``
may alternatively be a string or bytes, which will be parsed following
platform-dependent :ref:`quoting rules <subprocess-quoting>`.
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 +369,15 @@ async def _open_process(
)

if os.name == "posix":
if isinstance(command, str) and not options.get("shell"):
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 @@
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:

Check warning on line 306 in src/trio/_tools/gen_exports.py

View check run for this annotation

Codecov / codecov/patch

src/trio/_tools/gen_exports.py#L306

Added line #L306 was not covered by tests
f.write(new_source)
print("Regenerated sources successfully.")
if not matches_disk:
Expand Down
Loading