19
19
Optional ,
20
20
Tuple ,
21
21
Type ,
22
- Union ,
23
22
)
24
23
25
24
# Import some platform-specific things at top level so they can be mocked for
@@ -1075,7 +1074,7 @@ def start_timer(self, timeout: int) -> None:
1075
1074
self ._timer = threading .Timer (timeout , self .kill )
1076
1075
self ._timer .start ()
1077
1076
1078
- def read_proc_stdout (self , num_bytes : int ) -> Union [bytes , str , None ]:
1077
+ def read_proc_stdout (self , num_bytes : int ) -> Optional [bytes ]:
1079
1078
"""
1080
1079
Read ``num_bytes`` from the running process' stdout stream.
1081
1080
@@ -1087,7 +1086,7 @@ def read_proc_stdout(self, num_bytes: int) -> Union[bytes, str, None]:
1087
1086
"""
1088
1087
raise NotImplementedError
1089
1088
1090
- def read_proc_stderr (self , num_bytes : int ) -> Union [bytes , str , None ]:
1089
+ def read_proc_stderr (self , num_bytes : int ) -> Optional [bytes ]:
1091
1090
"""
1092
1091
Read ``num_bytes`` from the running process' stderr stream.
1093
1092
@@ -1154,11 +1153,13 @@ def send_interrupt(self, interrupt: "KeyboardInterrupt") -> None:
1154
1153
"""
1155
1154
self .write_proc_stdin ("\x03 " )
1156
1155
1157
- def returncode (self ) -> int :
1156
+ def returncode (self ) -> Optional [ int ] :
1158
1157
"""
1159
1158
Return the numeric return/exit code resulting from command execution.
1160
1159
1161
- :returns: `int`
1160
+ :returns:
1161
+ `int`, if any reasonable return code could be determined, or
1162
+ ``None`` in corner cases where that was not possible.
1162
1163
1163
1164
.. versionadded:: 1.0
1164
1165
"""
@@ -1238,7 +1239,7 @@ def should_use_pty(self, pty: bool = False, fallback: bool = True) -> bool:
1238
1239
use_pty = False
1239
1240
return use_pty
1240
1241
1241
- def read_proc_stdout (self , num_bytes : int ) -> Union [bytes , str , None ]:
1242
+ def read_proc_stdout (self , num_bytes : int ) -> Optional [bytes ]:
1242
1243
# Obtain useful read-some-bytes function
1243
1244
if self .using_pty :
1244
1245
# Need to handle spurious OSErrors on some Linux platforms.
@@ -1265,7 +1266,7 @@ def read_proc_stdout(self, num_bytes: int) -> Union[bytes, str, None]:
1265
1266
data = None
1266
1267
return data
1267
1268
1268
- def read_proc_stderr (self , num_bytes : int ) -> Union [bytes , str , None ]:
1269
+ def read_proc_stderr (self , num_bytes : int ) -> Optional [bytes ]:
1269
1270
# NOTE: when using a pty, this will never be called.
1270
1271
# TODO: do we ever get those OSErrors on stderr? Feels like we could?
1271
1272
if self .process and self .process .stderr :
@@ -1280,7 +1281,9 @@ def _write_proc_stdin(self, data: bytes) -> None:
1280
1281
elif self .process and self .process .stdin :
1281
1282
fd = self .process .stdin .fileno ()
1282
1283
else :
1283
- raise SubprocessPipeError ("No stdin process exists" )
1284
+ raise SubprocessPipeError (
1285
+ "Unable to write to missing subprocess or stdin!"
1286
+ )
1284
1287
# Try to write, ignoring broken pipes if encountered (implies child
1285
1288
# process exited before the process piping stdin to us finished;
1286
1289
# there's nothing we can do about that!)
@@ -1298,7 +1301,9 @@ def close_proc_stdin(self) -> None:
1298
1301
elif self .process and self .process .stdin :
1299
1302
self .process .stdin .close ()
1300
1303
else :
1301
- raise SubprocessPipeError ("No stdin process exists" )
1304
+ raise SubprocessPipeError (
1305
+ "Unable to close missing subprocess or stdin!"
1306
+ )
1302
1307
1303
1308
def start (self , command : str , shell : str , env : Dict [str , Any ]) -> None :
1304
1309
if self .using_pty :
@@ -1358,15 +1363,15 @@ def process_is_finished(self) -> bool:
1358
1363
else :
1359
1364
return self .process .poll () is not None
1360
1365
1361
- def returncode (self ) -> int :
1366
+ def returncode (self ) -> Optional [ int ] :
1362
1367
if self .using_pty :
1363
1368
# No subprocess.returncode available; use WIFEXITED/WIFSIGNALED to
1364
1369
# determine whch of WEXITSTATUS / WTERMSIG to use.
1365
1370
# TODO: is it safe to just say "call all WEXITSTATUS/WTERMSIG and
1366
1371
# return whichever one of them is nondefault"? Probably not?
1367
1372
# NOTE: doing this in an arbitrary order should be safe since only
1368
1373
# one of the WIF* methods ought to ever return True.
1369
- code = 0
1374
+ code = None
1370
1375
if os .WIFEXITED (self .status ):
1371
1376
code = os .WEXITSTATUS (self .status )
1372
1377
elif os .WIFSIGNALED (self .status ):
0 commit comments