Skip to content

Commit 1ac3c2f

Browse files
jdelicgvanrossum
authored andcommitted
update subprocess module stub for Python 3.5 (#426)
1 parent 5de7bfe commit 1ac3c2f

File tree

1 file changed

+146
-57
lines changed

1 file changed

+146
-57
lines changed

stdlib/3/subprocess.pyi

Lines changed: 146 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Stubs for subprocess
22

3-
# Based on http://docs.python.org/3.2/library/subprocess.html
3+
# Based on http://docs.python.org/3.5/library/subprocess.html
4+
import sys
45

56
import sys
67
from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union, List
@@ -20,7 +21,7 @@ if sys.version_info >= (3, 5):
2021

2122
# Nearly same args as Popen.__init__ except for timeout, input, and check
2223
def run(args: Union[str, Sequence[str]],
23-
timeout: int = ...,
24+
timeout: float = ...,
2425
input: Union[str, bytes] = ...,
2526
check: bool = ...,
2627
bufsize: int = ...,
@@ -41,73 +42,161 @@ if sys.version_info >= (3, 5):
4142
pass_fds: Any = ...) -> CompletedProcess: ...
4243

4344
# Same args as Popen.__init__
44-
def call(args: Union[str, Sequence[str]],
45-
bufsize: int = ...,
46-
executable: str = ...,
47-
stdin: Any = ...,
48-
stdout: Any = ...,
49-
stderr: Any = ...,
50-
preexec_fn: Callable[[], Any] = ...,
51-
close_fds: bool = ...,
52-
shell: bool = ...,
53-
cwd: str = ...,
54-
env: Mapping[str, str] = ...,
55-
universal_newlines: bool = ...,
56-
startupinfo: Any = ...,
57-
creationflags: int = ...,
58-
restore_signals: bool = ...,
59-
start_new_session: bool = ...,
60-
pass_fds: Any = ...) -> int: ...
45+
if sys.version_info >= (3, 3):
46+
# 3.3 added timeout
47+
def call(args: Union[str, Sequence[str]],
48+
bufsize: int = ...,
49+
executable: str = ...,
50+
stdin: Any = ...,
51+
stdout: Any = ...,
52+
stderr: Any = ...,
53+
preexec_fn: Callable[[], Any] = ...,
54+
close_fds: bool = ...,
55+
shell: bool = ...,
56+
cwd: str = ...,
57+
env: Mapping[str, str] = ...,
58+
universal_newlines: bool = ...,
59+
startupinfo: Any = ...,
60+
creationflags: int = ...,
61+
restore_signals: bool = ...,
62+
start_new_session: bool = ...,
63+
pass_fds: Any = ...,
64+
timeout: float = ...) -> int: ...
65+
else:
66+
def call(args: Union[str, Sequence[str]],
67+
bufsize: int = ...,
68+
executable: str = ...,
69+
stdin: Any = ...,
70+
stdout: Any = ...,
71+
stderr: Any = ...,
72+
preexec_fn: Callable[[], Any] = ...,
73+
close_fds: bool = ...,
74+
shell: bool = ...,
75+
cwd: str = ...,
76+
env: Mapping[str, str] = ...,
77+
universal_newlines: bool = ...,
78+
startupinfo: Any = ...,
79+
creationflags: int = ...,
80+
restore_signals: bool = ...,
81+
start_new_session: bool = ...,
82+
pass_fds: Any = ...) -> int: ...
6183

6284
# Same args as Popen.__init__
63-
def check_call(args: Union[str, Sequence[str]],
64-
bufsize: int = ...,
65-
executable: str = ...,
66-
stdin: Any = ...,
67-
stdout: Any = ...,
68-
stderr: Any = ...,
69-
preexec_fn: Callable[[], Any] = ...,
70-
close_fds: bool = ...,
71-
shell: bool = ...,
72-
cwd: str = ...,
73-
env: Mapping[str, str] = ...,
74-
universal_newlines: bool = ...,
75-
startupinfo: Any = ...,
76-
creationflags: int = ...,
77-
restore_signals: bool = ...,
78-
start_new_session: bool = ...,
79-
pass_fds: Any = ...) -> int: ...
80-
81-
# Same args as Popen.__init__, except for stdout
82-
def check_output(args: Union[str, Sequence[str]],
83-
bufsize: int = ...,
84-
executable: str = ...,
85-
stdin: Any = ...,
86-
stderr: Any = ...,
87-
preexec_fn: Callable[[], Any] = ...,
88-
close_fds: bool = ...,
89-
shell: bool = ...,
90-
cwd: str = ...,
91-
env: Mapping[str, str] = ...,
92-
universal_newlines: bool = ...,
93-
startupinfo: Any = ...,
94-
creationflags: int = ...,
95-
restore_signals: bool = ...,
96-
start_new_session: bool = ...,
97-
pass_fds: Any = ...) -> Any: ...
85+
if sys.version_info >= (3, 3):
86+
# 3.3 added timeout
87+
def check_call(args: Union[str, Sequence[str]],
88+
bufsize: int = ...,
89+
executable: str = ...,
90+
stdin: Any = ...,
91+
stdout: Any = ...,
92+
stderr: Any = ...,
93+
preexec_fn: Callable[[], Any] = ...,
94+
close_fds: bool = ...,
95+
shell: bool = ...,
96+
cwd: str = ...,
97+
env: Mapping[str, str] = ...,
98+
universal_newlines: bool = ...,
99+
startupinfo: Any = ...,
100+
creationflags: int = ...,
101+
restore_signals: bool = ...,
102+
start_new_session: bool = ...,
103+
pass_fds: Any = ...,
104+
timeout: float = ...) -> int: ...
105+
else:
106+
def check_call(args: Union[str, Sequence[str]],
107+
bufsize: int = ...,
108+
executable: str = ...,
109+
stdin: Any = ...,
110+
stdout: Any = ...,
111+
stderr: Any = ...,
112+
preexec_fn: Callable[[], Any] = ...,
113+
close_fds: bool = ...,
114+
shell: bool = ...,
115+
cwd: str = ...,
116+
env: Mapping[str, str] = ...,
117+
universal_newlines: bool = ...,
118+
startupinfo: Any = ...,
119+
creationflags: int = ...,
120+
restore_signals: bool = ...,
121+
start_new_session: bool = ...,
122+
pass_fds: Any = ...) -> int: ...
123+
124+
if sys.version_info >= (3, 4):
125+
# 3.4 added input
126+
def check_output(args: Union[str, Sequence[str]],
127+
bufsize: int = ...,
128+
executable: str = ...,
129+
stdin: Any = ...,
130+
stderr: Any = ...,
131+
preexec_fn: Callable[[], Any] = ...,
132+
close_fds: bool = ...,
133+
shell: bool = ...,
134+
cwd: str = ...,
135+
env: Mapping[str, str] = ...,
136+
universal_newlines: bool = ...,
137+
startupinfo: Any = ...,
138+
creationflags: int = ...,
139+
restore_signals: bool = ...,
140+
start_new_session: bool = ...,
141+
pass_fds: Any = ...,
142+
timeout: float = ...,
143+
input: Union[str, bytes] = ...) -> Any: ...
144+
elif sys.version_info >= (3, 3):
145+
# 3.3 added timeout
146+
def check_output(args: Union[str, Sequence[str]],
147+
bufsize: int = ...,
148+
executable: str = ...,
149+
stdin: Any = ...,
150+
stderr: Any = ...,
151+
preexec_fn: Callable[[], Any] = ...,
152+
close_fds: bool = ...,
153+
shell: bool = ...,
154+
cwd: str = ...,
155+
env: Mapping[str, str] = ...,
156+
universal_newlines: bool = ...,
157+
startupinfo: Any = ...,
158+
creationflags: int = ...,
159+
restore_signals: bool = ...,
160+
start_new_session: bool = ...,
161+
pass_fds: Any = ...,
162+
timeout: float = ...) -> Any: ...
163+
else:
164+
# Same args as Popen.__init__, except for stdout
165+
def check_output(args: Union[str, Sequence[str]],
166+
bufsize: int = ...,
167+
executable: str = ...,
168+
stdin: Any = ...,
169+
stderr: Any = ...,
170+
preexec_fn: Callable[[], Any] = ...,
171+
close_fds: bool = ...,
172+
shell: bool = ...,
173+
cwd: str = ...,
174+
env: Mapping[str, str] = ...,
175+
universal_newlines: bool = ...,
176+
startupinfo: Any = ...,
177+
creationflags: int = ...,
178+
restore_signals: bool = ...,
179+
start_new_session: bool = ...,
180+
pass_fds: Any = ...) -> Any: ...
181+
98182

99183
# TODO types
100184
PIPE = ... # type: Any
101185
STDOUT = ... # type: Any
102186
if sys.version_info >= (3, 3):
103-
DEVNULL = ... # type: Any
187+
DEVNULL = ... # type: Any
188+
class SubprocessError(Exception): ...
104189

105190

106191
class CalledProcessError(Exception):
107192
returncode = 0
108193
cmd = ... # type: str
109194
output = b'' # May be None
110195

196+
if sys.version_info >= (3, 5):
197+
stdout = b''
198+
stderr = b''
199+
111200
def __init__(self, returncode: int, cmd: str, output: Optional[str] = ...,
112201
stderr: Optional[str] = ...) -> None: ...
113202

@@ -141,9 +230,9 @@ class Popen:
141230
def wait(self) -> int: ...
142231
# Return str/bytes
143232
if sys.version_info >= (3, 3):
144-
def communicate(self, input=..., timeout: float = ...) -> Tuple[Any, Any]: ...
233+
def communicate(self, input: Union[str, bytes] = ..., timeout: float =...) -> Tuple[Any, Any]: ...
145234
else:
146-
def communicate(self, input=...) -> Tuple[Any, Any]: ...
235+
def communicate(self, input: Union[str, bytes] = ...) -> Tuple[Any, Any]: ...
147236
def send_signal(self, signal: int) -> None: ...
148237
def terminate(self) -> None: ...
149238
def kill(self) -> None: ...

0 commit comments

Comments
 (0)