@@ -5,6 +5,18 @@ import sys
5
5
from typing import Sequence , Any , Mapping , Callable , Tuple , IO , Optional , Union , List , Type , Text
6
6
from types import TracebackType
7
7
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
8
20
_FILE = Union [None , int , IO [Any ]]
9
21
_TXT = Union [bytes , Text ]
10
22
if sys .version_info >= (3 , 6 ):
@@ -250,7 +262,14 @@ STDOUT = ... # type: int
250
262
if sys .version_info >= (3 , 3 ):
251
263
DEVNULL = ... # type: int
252
264
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
254
273
255
274
256
275
class CalledProcessError (Exception ):
0 commit comments