mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
Improve types for subprocess module (#1059)
* Improve types for CalledProcessError This adds union types in the constructor to account for parameters that might be either byte strings or unicode strings. At the same time, this *removes* specific types from the user-accessible fields, to avoid the need for users to at every use site specify which types their particular instance was instantiated with. * remove 'moral' comments; add List import; change 'str' to 'Text' * import Text * List -> Sequence; reinsert 'moral' comments * Regularize string types everywhere This defines _TXT and _CMD aliases, and uses them everywhere applicable. Also brings the _FILE alias to python3. * fix typo; possibly fix indentation * remove trailing comma, which caused problems in python 2 tests * fix py2 outputs to be bytes; tweak descriptive comments; remove one AnyStr
This commit is contained in:
committed by
Jelle Zijlstra
parent
fb80dc3971
commit
62f57e4cef
@@ -2,65 +2,72 @@
|
||||
|
||||
# Based on http://docs.python.org/2/library/subprocess.html and Python 3 stub
|
||||
|
||||
from typing import Sequence, Any, AnyStr, Mapping, Callable, Tuple, IO, Union, Optional
|
||||
from typing import Sequence, Any, AnyStr, Mapping, Callable, Tuple, IO, Union, Optional, List, Text
|
||||
|
||||
_FILE = Union[int, IO[Any]]
|
||||
_TXT = Union[bytes, Text]
|
||||
_CMD = Union[_TXT, Sequence[_TXT]]
|
||||
|
||||
# Same args as Popen.__init__
|
||||
def call(args: Union[str, Sequence[str]],
|
||||
def call(args: _CMD,
|
||||
bufsize: int = ...,
|
||||
executable: str = ...,
|
||||
executable: _TXT = ...,
|
||||
stdin: _FILE = ...,
|
||||
stdout: _FILE = ...,
|
||||
stderr: _FILE = ...,
|
||||
preexec_fn: Callable[[], Any] = ...,
|
||||
close_fds: bool = ...,
|
||||
shell: bool = ...,
|
||||
cwd: str = ...,
|
||||
env: Mapping[str, str] = ...,
|
||||
cwd: _TXT = ...,
|
||||
env: Mapping[_TXT, _TXT] = ...,
|
||||
universal_newlines: bool = ...,
|
||||
startupinfo: Any = ...,
|
||||
creationflags: int = ...) -> int: ...
|
||||
|
||||
def check_call(args: Union[str, Sequence[str]],
|
||||
def check_call(args: _CMD,
|
||||
bufsize: int = ...,
|
||||
executable: str = ...,
|
||||
executable: _TXT = ...,
|
||||
stdin: _FILE = ...,
|
||||
stdout: _FILE = ...,
|
||||
stderr: _FILE = ...,
|
||||
preexec_fn: Callable[[], Any] = ...,
|
||||
close_fds: bool = ...,
|
||||
shell: bool = ...,
|
||||
cwd: str = ...,
|
||||
env: Mapping[str, str] = ...,
|
||||
cwd: _TXT = ...,
|
||||
env: Mapping[_TXT, _TXT] = ...,
|
||||
universal_newlines: bool = ...,
|
||||
startupinfo: Any = ...,
|
||||
creationflags: int = ...) -> int: ...
|
||||
|
||||
# Same args as Popen.__init__ except for stdout
|
||||
def check_output(args: Union[str, Sequence[str]],
|
||||
def check_output(args: _CMD,
|
||||
bufsize: int = ...,
|
||||
executable: str = ...,
|
||||
executable: _TXT = ...,
|
||||
stdin: _FILE = ...,
|
||||
stderr: _FILE = ...,
|
||||
preexec_fn: Callable[[], Any] = ...,
|
||||
close_fds: bool = ...,
|
||||
shell: bool = ...,
|
||||
cwd: str = ...,
|
||||
env: Mapping[str, str] = ...,
|
||||
cwd: _TXT = ...,
|
||||
env: Mapping[_TXT, _TXT] = ...,
|
||||
universal_newlines: bool = ...,
|
||||
startupinfo: Any = ...,
|
||||
creationflags: int = ...) -> str: ...
|
||||
creationflags: int = ...) -> bytes: ...
|
||||
|
||||
PIPE = ... # type: int
|
||||
STDOUT = ... # type: int
|
||||
|
||||
class CalledProcessError(Exception):
|
||||
returncode = 0
|
||||
cmd = ... # type: str
|
||||
output = ... # type: str # May be None
|
||||
# morally: _CMD
|
||||
cmd = ... # type: Any
|
||||
# morally: Optional[bytes]
|
||||
output = ... # type: Any
|
||||
|
||||
def __init__(self, returncode: int, cmd: str, output: Optional[str] = ...) -> None: ...
|
||||
def __init__(self,
|
||||
returncode: int,
|
||||
cmd: _CMD,
|
||||
output: Optional[bytes] = ...) -> None: ...
|
||||
|
||||
class Popen:
|
||||
stdin = ... # type: Optional[IO[Any]]
|
||||
@@ -70,33 +77,31 @@ class Popen:
|
||||
returncode = 0
|
||||
|
||||
def __init__(self,
|
||||
args: Union[str, Sequence[str]],
|
||||
args: _CMD,
|
||||
bufsize: int = ...,
|
||||
executable: Optional[str] = ...,
|
||||
executable: Optional[_TXT] = ...,
|
||||
stdin: Optional[_FILE] = ...,
|
||||
stdout: Optional[_FILE] = ...,
|
||||
stderr: Optional[_FILE] = ...,
|
||||
preexec_fn: Optional[Callable[[], Any]] = ...,
|
||||
close_fds: bool = ...,
|
||||
shell: bool = ...,
|
||||
cwd: Optional[str] = ...,
|
||||
env: Optional[Mapping[str, str]] = ...,
|
||||
cwd: Optional[_TXT] = ...,
|
||||
env: Optional[Mapping[_TXT, _TXT]] = ...,
|
||||
universal_newlines: bool = ...,
|
||||
startupinfo: Optional[Any] = ...,
|
||||
creationflags: int = ...) -> None: ...
|
||||
|
||||
def poll(self) -> int: ...
|
||||
def wait(self) -> int: ...
|
||||
def communicate(self, input: Optional[AnyStr] = ...) -> Tuple[Optional[bytes], Optional[bytes]]: ...
|
||||
# morally: -> Tuple[Optional[bytes], Optional[bytes]]
|
||||
def communicate(self, input: Optional[_TXT] = ...) -> Tuple[Any, Any]: ...
|
||||
def send_signal(self, signal: int) -> None: ...
|
||||
def terminate(self) -> None: ...
|
||||
def kill(self) -> None: ...
|
||||
def __enter__(self) -> 'Popen': ...
|
||||
def __exit__(self, type, value, traceback) -> bool: ...
|
||||
|
||||
def getstatusoutput(cmd: str) -> Tuple[int, str]: ...
|
||||
def getoutput(cmd: str) -> str: ...
|
||||
|
||||
# Windows-only: STARTUPINFO etc.
|
||||
|
||||
STD_INPUT_HANDLE = ... # type: Any
|
||||
|
||||
Reference in New Issue
Block a user