Skip to content

Commit 90c2c22

Browse files
authored
Make python 2 subprocess consistent with python 3 (#3132)
1 parent dad16f2 commit 90c2c22

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

stdlib/2/subprocess.pyi

+12-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
# Based on http://docs.python.org/2/library/subprocess.html and Python 3 stub
44

5-
from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Union, Optional, List, Text
5+
from typing import (
6+
Sequence, Any, Mapping, Callable, Tuple, IO, Union, Optional, List, Text, TypeVar, Generic,
7+
)
8+
9+
# This is a dummy type variable used to make Popen generic like it is in python 3
10+
_T = TypeVar('_T', bound=bytes)
611

712
_FILE = Union[None, int, IO[Any]]
813
_TXT = Union[bytes, Text]
@@ -63,17 +68,17 @@ class CalledProcessError(Exception):
6368
# morally: _CMD
6469
cmd: Any
6570
# morally: Optional[bytes]
66-
output: Any
71+
output: bytes
6772

6873
def __init__(self,
6974
returncode: int,
7075
cmd: _CMD,
7176
output: Optional[bytes] = ...) -> None: ...
7277

73-
class Popen:
74-
stdin: Optional[IO[Any]]
75-
stdout: Optional[IO[Any]]
76-
stderr: Optional[IO[Any]]
78+
class Popen(Generic[_T]):
79+
stdin: Optional[IO[bytes]]
80+
stdout: Optional[IO[bytes]]
81+
stderr: Optional[IO[bytes]]
7782
pid = 0
7883
returncode = 0
7984

@@ -96,7 +101,7 @@ class Popen:
96101
def poll(self) -> int: ...
97102
def wait(self) -> int: ...
98103
# morally: -> Tuple[Optional[bytes], Optional[bytes]]
99-
def communicate(self, input: Optional[_TXT] = ...) -> Tuple[Any, Any]: ...
104+
def communicate(self, input: Optional[_TXT] = ...) -> Tuple[bytes, bytes]: ...
100105
def send_signal(self, signal: int) -> None: ...
101106
def terminate(self) -> None: ...
102107
def kill(self) -> None: ...

0 commit comments

Comments
 (0)