Skip to content

Commit 3b26b45

Browse files
committed
fix(AsyncTmuxCmd): Handle text decoding manually for async subprocess
The AsyncTmuxCmd class was updated to handle text decoding manually since asyncio.create_subprocess_exec() doesn't support the text=True parameter that subprocess.Popen() supports. Changes: - Remove text=True and errors=backslashreplace from create_subprocess_exec() - Handle bytes output by manually decoding with decode(errors="backslashreplace") - Keep string processing logic consistent with tmux_cmd class This fixes the ValueError("text must be False") error that occurred when trying to use text mode with asyncio subprocesses. The async version now properly handles text decoding while maintaining the same behavior as the synchronous tmux_cmd class.
1 parent a461be9 commit 3b26b45

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/libtmux/common.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,8 @@ async def run(cls, *args: t.Any) -> AsyncTmuxCmd:
368368
*cmd,
369369
stdout=asyncio.subprocess.PIPE,
370370
stderr=asyncio.subprocess.PIPE,
371-
text=True,
372-
errors="backslashreplace",
373371
)
374-
stdout, stderr = await process.communicate()
372+
stdout_bytes, stderr_bytes = await process.communicate()
375373
returncode: int = (
376374
process.returncode if process.returncode is not None else -1
377375
)
@@ -383,6 +381,10 @@ async def run(cls, *args: t.Any) -> AsyncTmuxCmd:
383381
msg,
384382
) from e
385383

384+
# Decode bytes to string with error handling
385+
stdout = stdout_bytes.decode(errors="backslashreplace")
386+
stderr = stderr_bytes.decode(errors="backslashreplace")
387+
386388
# Split on newlines and filter empty lines
387389
stdout_split: list[str] = stdout.split("\n")
388390
# remove trailing newlines from stdout

0 commit comments

Comments
 (0)