mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
Add subprocess annotation for TimeoutExpired (#1954)
This commit is contained in:
committed by
Guido van Rossum
parent
00efd76861
commit
5af337b438
@@ -5,6 +5,18 @@ import sys
|
||||
from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union, List, Type, Text
|
||||
from types import TracebackType
|
||||
|
||||
# We prefer to annotate inputs to methods (eg subprocess.check_call) with these
|
||||
# union types. However, outputs (eg check_call return) and class attributes
|
||||
# (eg TimeoutError.cmd) we prefer to annotate with Any, so the caller does not
|
||||
# have to use an assertion to confirm which type.
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# try:
|
||||
# x = subprocess.check_output(["ls", "-l"])
|
||||
# reveal_type(x) # Any, but morally is _TXT
|
||||
# except TimeoutError as e:
|
||||
# reveal_type(e.cmd) # Any, but morally is _CMD
|
||||
_FILE = Union[None, int, IO[Any]]
|
||||
_TXT = Union[bytes, Text]
|
||||
if sys.version_info >= (3, 6):
|
||||
@@ -250,7 +262,14 @@ STDOUT = ... # type: int
|
||||
if sys.version_info >= (3, 3):
|
||||
DEVNULL = ... # type: int
|
||||
class SubprocessError(Exception): ...
|
||||
class TimeoutExpired(SubprocessError): ...
|
||||
class TimeoutExpired(SubprocessError):
|
||||
# morally: _CMD
|
||||
cmd = ... # type: Any
|
||||
timeout = ... # type: float
|
||||
# morally: Optional[_TXT]
|
||||
output = ... # type: Any
|
||||
stdout = ... # type: Any
|
||||
stderr = ... # type: Any
|
||||
|
||||
|
||||
class CalledProcessError(Exception):
|
||||
|
||||
Reference in New Issue
Block a user