Skip to content

Commit 5af337b

Browse files
nipunn1313gvanrossum
authored andcommitted
Add subprocess annotation for TimeoutExpired (#1954)
1 parent 00efd76 commit 5af337b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

stdlib/3/subprocess.pyi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ import sys
55
from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union, List, Type, Text
66
from types import TracebackType
77

8+
# We prefer to annotate inputs to methods (eg subprocess.check_call) with these
9+
# union types. However, outputs (eg check_call return) and class attributes
10+
# (eg TimeoutError.cmd) we prefer to annotate with Any, so the caller does not
11+
# have to use an assertion to confirm which type.
12+
#
13+
# For example:
14+
#
15+
# try:
16+
# x = subprocess.check_output(["ls", "-l"])
17+
# reveal_type(x) # Any, but morally is _TXT
18+
# except TimeoutError as e:
19+
# reveal_type(e.cmd) # Any, but morally is _CMD
820
_FILE = Union[None, int, IO[Any]]
921
_TXT = Union[bytes, Text]
1022
if sys.version_info >= (3, 6):
@@ -250,7 +262,14 @@ STDOUT = ... # type: int
250262
if sys.version_info >= (3, 3):
251263
DEVNULL = ... # type: int
252264
class SubprocessError(Exception): ...
253-
class TimeoutExpired(SubprocessError): ...
265+
class TimeoutExpired(SubprocessError):
266+
# morally: _CMD
267+
cmd = ... # type: Any
268+
timeout = ... # type: float
269+
# morally: Optional[_TXT]
270+
output = ... # type: Any
271+
stdout = ... # type: Any
272+
stderr = ... # type: Any
254273

255274

256275
class CalledProcessError(Exception):

0 commit comments

Comments
 (0)