Skip to content

Commit ea734c6

Browse files
timabbottgvanrossum
authored andcommitted
Fix subprocess stubs (#198)
* subprocess.CalledProcessError output argument is optional. * subprocess.CalledProcessError takes stderr argument in python3. * subprocess: Fix type for command in call() and friends. The stubs didn't correctly support the fact that you can pass a string as well as a sequence of strings.
1 parent 9fdac6e commit ea734c6

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

stdlib/2.7/subprocess.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ _FILE = Union[int, IO[Any]]
88

99
# TODO force keyword arguments
1010
# TODO more keyword arguments (from Popen)
11-
def call(args: Sequence[str], *,
11+
def call(args: Union[str, Sequence[str]], *,
1212
stdin: _FILE = ..., stdout: _FILE = ..., stderr: _FILE = ...,
1313
shell: bool = ..., env: Mapping[str, str] = ...,
1414
cwd: str = ...) -> int: ...
15-
def check_call(args: Sequence[str], *,
15+
def check_call(args: Union[str, Sequence[str]], *,
1616
stdin: _FILE = ..., stdout: _FILE = ..., stderr: _FILE = ...,
1717
shell: bool = ..., env: Mapping[str, str] = ..., cwd: str = ...,
1818
close_fds: Sequence[_FILE] = ..., preexec_fn: Callable[[], Any] = ...) -> int: ...
19-
def check_output(args: Sequence[str], *,
19+
def check_output(args: Union[str, Sequence[str]], *,
2020
stdin: _FILE = ..., stderr: _FILE = ...,
2121
shell: bool = ..., universal_newlines: bool = ...,
2222
env: Mapping[str, str] = ..., cwd: str = ...) -> str: ...
@@ -29,7 +29,7 @@ class CalledProcessError(Exception):
2929
cmd = ... # type: str
3030
output = ... # type: str # May be None
3131

32-
def __init__(self, returncode: int, cmd: str, output: str = ...) -> None: ...
32+
def __init__(self, returncode: int, cmd: str, output: Optional[str] = ...) -> None: ...
3333

3434
class Popen:
3535
stdin = ... # type: Optional[IO[Any]]
@@ -39,7 +39,7 @@ class Popen:
3939
returncode = 0
4040

4141
def __init__(self,
42-
args: Sequence[str],
42+
args: Union[str, Sequence[str]],
4343
bufsize: int = ...,
4444
executable: str = ...,
4545
stdin: _FILE = ...,

stdlib/3/subprocess.pyi

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
# Based on http://docs.python.org/3.2/library/subprocess.html
44

5-
from typing import Sequence, Any, Mapping, Callable, Tuple, IO
5+
from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union
66

77
# TODO force keyword arguments
88
# TODO more keyword arguments
9-
def call(args: Sequence[str], *, stdin: Any = ..., stdout: Any = ...,
9+
def call(args: Union[str, Sequence[str]], *, stdin: Any = ..., stdout: Any = ...,
1010
stderr: Any = ..., shell: bool = ...,
1111
env: Mapping[str, str] = ...,
1212
cwd: str = ...) -> int: ...
13-
def check_call(args: Sequence[str], *, stdin: Any = ..., stdout: Any = ...,
13+
def check_call(args: Union[str, Sequence[str]], *, stdin: Any = ..., stdout: Any = ...,
1414
stderr: Any = ..., shell: bool = ...,
1515
env: Mapping[str, str] = ...,
1616
cwd: str = ...) -> int: ...
1717
# Return str/bytes
18-
def check_output(args: Sequence[str], *, stdin: Any = ..., stderr: Any = ...,
18+
def check_output(args: Union[str, Sequence[str]], *, stdin: Any = ..., stderr: Any = ...,
1919
shell: bool = ..., universal_newlines: bool = ...,
2020
env: Mapping[str, str] = ...,
2121
cwd: str = ...) -> Any: ...
@@ -29,7 +29,8 @@ class CalledProcessError(Exception):
2929
cmd = ... # type: str
3030
output = b'' # May be None
3131

32-
def __init__(self, returncode: int, cmd: str, output: str = ...) -> None: ...
32+
def __init__(self, returncode: int, cmd: str, output: Optional[str],
33+
stderr: Optional[str] = ...) -> None: ...
3334

3435
class Popen:
3536
stdin = ... # type: IO[Any]
@@ -39,7 +40,7 @@ class Popen:
3940
returncode = 0
4041

4142
def __init__(self,
42-
args: Sequence[str],
43+
args: Union[str, Sequence[str]],
4344
bufsize: int = ...,
4445
executable: str = ...,
4546
stdin: Any = ...,

0 commit comments

Comments
 (0)