From a816e872916bccac0272dc86502260ef11024318 Mon Sep 17 00:00:00 2001 From: Jonas Maurus Date: Mon, 1 Aug 2016 21:46:33 +0000 Subject: [PATCH 1/6] update subprocess stub to Python 3.4/3.5 signatures --- stdlib/3/subprocess.pyi | 227 ++++++++++++++++++++++++++++++---------- 1 file changed, 173 insertions(+), 54 deletions(-) diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index 43934b5efa84..80dfe2b25b89 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -1,74 +1,187 @@ # Stubs for subprocess -# Based on http://docs.python.org/3.2/library/subprocess.html +# Based on http://docs.python.org/3.5/library/subprocess.html +import sys from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union # Same args as Popen.__init__ -def call(args: Union[str, Sequence[str]], - bufsize: int = ..., - executable: str = ..., - stdin: Any = ..., - stdout: Any = ..., - stderr: Any = ..., - preexec_fn: Callable[[], Any] = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: str = ..., - env: Mapping[str, str] = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ...) -> int: ... +if sys.version_info >= (3, 3): + def call(args: Union[str, Sequence[str]], + bufsize: int = ..., + executable: str = ..., + stdin: Any = ..., + stdout: Any = ..., + stderr: Any = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: str = ..., + env: Mapping[str, str] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: int = ...) -> int: ... +else: + def call(args: Union[str, Sequence[str]], + bufsize: int = ..., + executable: str = ..., + stdin: Any = ..., + stdout: Any = ..., + stderr: Any = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: str = ..., + env: Mapping[str, str] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ...) -> int: ... # Same args as Popen.__init__ -def check_call(args: Union[str, Sequence[str]], - bufsize: int = ..., - executable: str = ..., - stdin: Any = ..., - stdout: Any = ..., - stderr: Any = ..., - preexec_fn: Callable[[], Any] = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: str = ..., - env: Mapping[str, str] = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ...) -> int: ... - -# Same args as Popen.__init__, except for stdout -def check_output(args: Union[str, Sequence[str]], - bufsize: int = ..., - executable: str = ..., - stdin: Any = ..., - stderr: Any = ..., - preexec_fn: Callable[[], Any] = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: str = ..., - env: Mapping[str, str] = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ...) -> Any: ... +if sys.version_info >= (3, 3): + def check_call(args: Union[str, Sequence[str]], + bufsize: int = ..., + executable: str = ..., + stdin: Any = ..., + stdout: Any = ..., + stderr: Any = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: str = ..., + env: Mapping[str, str] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: int = ...) -> int: ... +else: + def check_call(args: Union[str, Sequence[str]], + bufsize: int = ..., + executable: str = ..., + stdin: Any = ..., + stdout: Any = ..., + stderr: Any = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: str = ..., + env: Mapping[str, str] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ...) -> int: ... + +if sys.version_info >= (3, 4): + # the input= keyword was added in 3.4 + def check_output(args: Union[str, Sequence[str]], + bufsize: int = ..., + executable: str = ..., + stdin: Any = ..., + stderr: Any = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: str = ..., + env: Mapping[str, str] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: int = ..., + input: Union[str, bytes] = ...) -> Any: ... +elif sys.version_info >= (3, 3): + def check_output(args: Union[str, Sequence[str]], + bufsize: int = ..., + executable: str = ..., + stdin: Any = ..., + stderr: Any = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: str = ..., + env: Mapping[str, str] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: int = ...) -> Any: ... +else: + # Same args as Popen.__init__, except for stdout + def check_output(args: Union[str, Sequence[str]], + bufsize: int = ..., + executable: str = ..., + stdin: Any = ..., + stderr: Any = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: str = ..., + env: Mapping[str, str] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ...) -> Any: ... + + +if sys.version_info >= (3, 5): + # Same args as Popen.__init__, except for timeout, input and check + def run(args: Union[str, Sequence[str]], + bufsize: int = ..., + executable: str = ..., + stdin: Any = ..., + stderr: Any = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: str = ..., + env: Mapping[str, str] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + input: Union[str, bytes] = ..., + timeout: int = None, + check: bool = False) -> Any: ... + # TODO types PIPE = ... # type: Any STDOUT = ... # type: Any +if sys.version_info >= (3, 3): + DEVNULL = ... # type: Any + class SubprocessError(Exception): ... + + class CalledProcessError(Exception): returncode = 0 cmd = ... # type: str output = b'' # May be None + if sys.version_info >= (3, 5): + stdout = b'' + stderr = b'' + def __init__(self, returncode: int, cmd: str, output: Optional[str] = ..., stderr: Optional[str] = ...) -> None: ... @@ -79,6 +192,9 @@ class Popen: pid = 0 returncode = 0 + if sys.version_info >= (3, 3): + args = Union[str, Sequence[str]] + def __init__(self, args: Union[str, Sequence[str]], bufsize: int = ..., @@ -101,7 +217,10 @@ class Popen: def poll(self) -> int: ... def wait(self) -> int: ... # Return str/bytes - def communicate(self, input=...) -> Tuple[Any, Any]: ... + if sys.version_info >= (3, 3): + def communicate(self, input: Union[str, bytes]=..., timeout: int=...) -> Tuple[Any, Any]: ... + else: + def communicate(self, input: Union[str, bytes]=...) -> Tuple[Any, Any]: ... def send_signal(self, signal: int) -> None: ... def terminate(self) -> None: ... def kill(self) -> None: ... From c65b0b9d8075bf035538c21c66f2f49355259631 Mon Sep 17 00:00:00 2001 From: Jonas Maurus Date: Mon, 1 Aug 2016 22:19:29 +0000 Subject: [PATCH 2/6] better comments --- stdlib/3/subprocess.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index 80dfe2b25b89..c432597f4851 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -7,6 +7,7 @@ from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union # Same args as Popen.__init__ if sys.version_info >= (3, 3): + # 3.3 added timeout def call(args: Union[str, Sequence[str]], bufsize: int = ..., executable: str = ..., @@ -46,6 +47,7 @@ else: # Same args as Popen.__init__ if sys.version_info >= (3, 3): + # 3.3 added timeout def check_call(args: Union[str, Sequence[str]], bufsize: int = ..., executable: str = ..., @@ -84,7 +86,7 @@ else: pass_fds: Any = ...) -> int: ... if sys.version_info >= (3, 4): - # the input= keyword was added in 3.4 + # 3.4 added input def check_output(args: Union[str, Sequence[str]], bufsize: int = ..., executable: str = ..., @@ -104,6 +106,7 @@ if sys.version_info >= (3, 4): timeout: int = ..., input: Union[str, bytes] = ...) -> Any: ... elif sys.version_info >= (3, 3): + # 3.3 added timeout def check_output(args: Union[str, Sequence[str]], bufsize: int = ..., executable: str = ..., From 9dec1909e5439fccf11a5da8f16d3a3d460be7bd Mon Sep 17 00:00:00 2001 From: Jonas Maurus Date: Fri, 5 Aug 2016 20:33:10 +0000 Subject: [PATCH 3/6] newest upstream commit to subprocess.py uses timeout: float, so I do too --- stdlib/3/subprocess.pyi | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index 2fffa7d4f6b1..8f1697cf0b71 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -21,7 +21,7 @@ if sys.version_info >= (3, 5): # Nearly same args as Popen.__init__ except for timeout, input, and check def run(args: Union[str, Sequence[str]], - timeout: int = ..., + timeout: float = ..., input: Union[str, bytes] = ..., check: bool = ..., bufsize: int = ..., @@ -61,7 +61,7 @@ if sys.version_info >= (3, 3): restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - timeout: int = ...) -> int: ... + timeout: float = ...) -> int: ... else: def call(args: Union[str, Sequence[str]], bufsize: int = ..., @@ -101,7 +101,7 @@ if sys.version_info >= (3, 3): restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - timeout: int = ...) -> int: ... + timeout: float = ...) -> int: ... else: def check_call(args: Union[str, Sequence[str]], bufsize: int = ..., @@ -139,7 +139,7 @@ if sys.version_info >= (3, 4): restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - timeout: int = ..., + timeout: float = ..., input: Union[str, bytes] = ...) -> Any: ... elif sys.version_info >= (3, 3): # 3.3 added timeout @@ -159,7 +159,7 @@ elif sys.version_info >= (3, 3): restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - timeout: int = ...) -> Any: ... + timeout: float = ...) -> Any: ... else: # Same args as Popen.__init__, except for stdout def check_output(args: Union[str, Sequence[str]], @@ -199,7 +199,7 @@ if sys.version_info >= (3, 5): start_new_session: bool = ..., pass_fds: Any = ..., input: Union[str, bytes] = ..., - timeout: int = None, + timeout: float = None, check: bool = False) -> Any: ... @@ -260,9 +260,9 @@ class Popen: def wait(self) -> int: ... # Return str/bytes if sys.version_info >= (3, 3): - def communicate(self, input: Union[str, bytes]=..., timeout: float=...) -> Tuple[Any, Any]: ... + def communicate(self, input: Union[str, bytes] = ..., timeout: float =...) -> Tuple[Any, Any]: ... else: - def communicate(self, input: Union[str, bytes]=...) -> Tuple[Any, Any]: ... + def communicate(self, input: Union[str, bytes] = ...) -> Tuple[Any, Any]: ... def send_signal(self, signal: int) -> None: ... def terminate(self) -> None: ... def kill(self) -> None: ... From 78e526b5431f7ed30573da71755c0e2eb9655af8 Mon Sep 17 00:00:00 2001 From: Jonas Maurus Date: Fri, 5 Aug 2016 21:07:09 +0000 Subject: [PATCH 4/6] remove redefinition of DEVNULL --- stdlib/3/subprocess.pyi | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index 8f1697cf0b71..b9f223a8c1db 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -206,10 +206,6 @@ if sys.version_info >= (3, 5): # TODO types PIPE = ... # type: Any STDOUT = ... # type: Any -if sys.version_info >= (3, 3): - DEVNULL = ... # type: Any - - if sys.version_info >= (3, 3): DEVNULL = ... # type: Any class SubprocessError(Exception): ... From f61fd6f8a1794dd64c0a89c3b2cc4149101d8cf6 Mon Sep 17 00:00:00 2001 From: Jonas Maurus Date: Fri, 5 Aug 2016 22:25:11 +0000 Subject: [PATCH 5/6] remove double definition of run() created by runaway merge of upstream master --- stdlib/3/subprocess.pyi | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index b9f223a8c1db..99e05c0adc2c 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -180,29 +180,6 @@ else: pass_fds: Any = ...) -> Any: ... -if sys.version_info >= (3, 5): - # Same args as Popen.__init__, except for timeout, input and check - def run(args: Union[str, Sequence[str]], - bufsize: int = ..., - executable: str = ..., - stdin: Any = ..., - stderr: Any = ..., - preexec_fn: Callable[[], Any] = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: str = ..., - env: Mapping[str, str] = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - input: Union[str, bytes] = ..., - timeout: float = None, - check: bool = False) -> Any: ... - - # TODO types PIPE = ... # type: Any STDOUT = ... # type: Any From a2725f6e79b2a044813b1c9d01499d09150e34ff Mon Sep 17 00:00:00 2001 From: Jonas Maurus Date: Fri, 5 Aug 2016 22:32:47 +0000 Subject: [PATCH 6/6] remove unused typedef --- stdlib/3/subprocess.pyi | 3 --- 1 file changed, 3 deletions(-) diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index 99e05c0adc2c..880b08ed6fad 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -207,9 +207,6 @@ class Popen: pid = 0 returncode = 0 - if sys.version_info >= (3, 3): - args = Union[str, Sequence[str]] - def __init__(self, args: Union[str, Sequence[str]], bufsize: int = ...,