Commit c8998aee authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Rename exec_io's 'data' arg to 'input'; matches subprocess & Executor

parent 4f68e8d9
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ from typing import SupportsBytes
from typing import TypeVar
from typing import Union
from typing import overload
from warnings import warn

import trio.abc

@@ -57,7 +58,7 @@ def coerce_args(args: Arguments) -> Iterator[str]:
@overload
def exec_io(
	cmd: Arguments, *,
	data: bytes = b'',
	input: bytes = b'',
	deserialiser: Deserialiser[T],
	**kwargs: Any,
) -> T: ...
@@ -66,7 +67,7 @@ def exec_io(
@overload
def exec_io(
	cmd: Arguments, *,
	data: bytes = b'',
	input: bytes = b'',
	deserialiser: None = None,
	**kwargs: Any,
) -> int: ...
@@ -74,14 +75,14 @@ def exec_io(

def exec_io(
	cmd: Arguments, *,
	data: bytes = b'',
	input: bytes = b'',
	deserialiser: Deserialiser[Any]|None = None,
	**kwargs: Any,
) -> Any:
	"""
	Execute a command, handling output asynchronously

	If data is provided it will be fed to the process' stdin.
	If input is provided it will be fed to the process' stdin.
	If a deserialiser is provided it will be used to parse stdout data from the process.

	Stderr and stdout (if no deserialiser is provided) will be written to `sys.stderr` and
@@ -92,11 +93,16 @@ def exec_io(
	"""
	if deserialiser and 'stdout' in kwargs:
		raise TypeError("Cannot provide 'deserialiser' with 'stdout' argument")
	if data and 'stdin' in kwargs:
		raise TypeError("Cannot provide 'data' with 'stdin' argument")
	if "data" in kwargs:
		if input:
			raise TypeError("both 'input' and the deprecated 'data' keywords provided")
		warn(DeprecationWarning("the 'data' keyword argument is deprecated, use 'input'"))
		input = kwargs.pop("data")
	if input and 'stdin' in kwargs:
		raise TypeError("Cannot provide 'input' with 'stdin' argument")
	stdout: IO[str]|IO[bytes]|int = io.BytesIO() if deserialiser else kwargs.pop('stdout', sys.stdout)
	stderr: IO[str]|IO[bytes]|int = kwargs.pop('stderr', sys.stderr)
	proc = trio.run(_exec_io, cmd, data, stdout, stderr, kwargs)
	proc = trio.run(_exec_io, cmd, input, stdout, stderr, kwargs)
	if deserialiser:
		assert isinstance(stdout, io.BytesIO)
		return deserialiser(stdout.getbuffer())