Skip to content
Merged
Changes from all 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
4 changes: 1 addition & 3 deletions src/loopzero/_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ def build_env(
) -> dict[str, str]:
"""Copy only allowlisted variables from the current environment, then apply extras."""
env = {key: os.environ[key] for key in env_allowlist if key in os.environ}
if extra_env:
env.update(extra_env)
env.update(extra_env or {})
return env


Expand Down Expand Up @@ -138,7 +137,6 @@ def run(
stdin=subprocess.PIPE if input is not None else subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT if merge_output else subprocess.PIPE,
text=not preserve_newlines,
encoding=None if preserve_newlines else encoding,
errors=None if preserve_newlines else "replace",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Text vs. bytes mode now depends implicitly on the errors argument

The change doesn't alter behavior. Popen turns on text mode when encoding, errors, text or universal_newlines is set. In the default path, errors="replace" is always set, even when encoding is None, so stdout and stderr are still decoded with universal newlines. In the preserve_newlines path, all three are None, so the pipes stay in bytes mode and the decode at lines 167-170 still runs. The risk is for future edits: the mode choice now depends on a side effect of errors. If someone later drops errors="replace" or passes it in both branches, the mode would quietly flip. That would return bytes where str is expected, or translate CRLF in raw mode. Smallest fix, with no line cost: add a short comment on line 141 saying errors also selects text mode. A regression test that asserts the decoded-mode CRLF→LF translation would also catch it.

start_new_session=os.name == "posix",
Expand Down
Loading