Skip to content

Commit ee1930d

Browse files
committed
Merge pull request #15 from o11c/lots
Lots of stub fixes
2 parents e4a7edb + c2f892a commit ee1930d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+542
-303
lines changed

builtins/2.7/_functools.pyi

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
"""Stub file for the '_functools' module."""
22

3-
from typing import Any, Callable, Iterator, Optional, TypeVar, Tuple
3+
from typing import Any, Callable, Dict, Iterator, Optional, TypeVar, Tuple, overload
44

55
_T = TypeVar("_T")
6+
7+
@overload
8+
def reduce(function: Callable[[_T, _T], _T],
9+
sequence: Iterator[_T]) -> _T: ...
10+
@overload
611
def reduce(function: Callable[[_T, _T], _T],
7-
sequence: Iterator[_T], initial=Optional[_T]) -> _T: ...
12+
sequence: Iterator[_T], initial: _T) -> _T: ...
813

914
class partial(object):
1015
func = ... # type: Callable[..., Any]
11-
args = ... # type: Tuple[Any]
16+
args = ... # type: Tuple[Any, ...]
1217
keywords = ... # type: Dict[str, Any]
13-
def __init__(self, func: Callable[..., Any], *args, **kwargs) -> None: ...
14-
def __call__(self, *args, **kwargs) -> Any: ...
18+
def __init__(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ...
19+
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...

builtins/2.7/_random.pyi

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
from typing import Optional, Union, Any
1+
from typing import Tuple
2+
3+
# Actually Tuple[(int,) * 625]
4+
_State = Tuple[int, ...]
25

36
class Random(object):
4-
def __init__(self, seed: Optional[Union[int, Any]] = ..., object = ...) -> None: ...
5-
def getstate(self) -> tuple: ...
6-
def setstate(self, state: tuple) -> None: ...
7+
def __init__(self, seed: object = None) -> None: ...
8+
def seed(self, x: object = None) -> None: ...
9+
def getstate(self) -> _State: ...
10+
def setstate(self, state: _State) -> None: ...
711
def random(self) -> float: ...
812
def getrandbits(self, k: int) -> int: ...
913
def jumpahead(self, i: int) -> None: ...

builtins/2.7/_warnings.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, List
22

33
default_action = ... # type: str
44
filters = ... # type: List[tuple]

builtins/2.7/array.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Stub file for the 'array' module."""
22

33
from typing import (Any, Generic, IO, Iterable, Sequence, TypeVar,
4-
Union, overload, Iterator, Tuple, BinaryIO)
4+
Union, overload, Iterator, Tuple, BinaryIO, List)
55

66
T = TypeVar('T')
77

builtins/2.7/builtins.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Stubs for builtins (Python 2.7)
22

33
from typing import (
4-
Optional, TypeVar, Iterator, Iterable, overload,
4+
TypeVar, Iterator, Iterable, overload,
55
Sequence, Mapping, Tuple, List, Any, Dict, Callable, Generic, Set,
66
AbstractSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs,
77
SupportsRound, IO, BinaryIO, Union, AnyStr, MutableSequence, MutableMapping,
@@ -496,6 +496,7 @@ class list(MutableSequence[_T], Reversible[_T], Generic[_T]):
496496
def __delitem__(self, i: Union[int, slice]) -> None: ...
497497
def __delslice(self, start: int, stop: int) -> None: ...
498498
def __add__(self, x: List[_T]) -> List[_T]: ...
499+
def __iadd__(self, x: Iterable[_T]) -> List[_T]: ...
499500
def __mul__(self, n: int) -> List[_T]: ...
500501
def __rmul__(self, n: int) -> List[_T]: ...
501502
def __contains__(self, o: object) -> bool: ...

builtins/2.7/cPickle.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, IO
1+
from typing import Any, IO, List
22

33
HIGHEST_PROTOCOL = ... # type: int
44
compatible_formats = ... # type: List[str]

builtins/2.7/cStringIO.pyi

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
11
# Stubs for cStringIO (Python 2.7)
22
# See https://docs.python.org/2/library/stringio.html
33

4-
from typing import IO, List, Iterable, Iterator, Any, Union
4+
from typing import overload, IO, List, Iterable, Iterator, Optional, Union
5+
from types import TracebackType
56

6-
class StringIO(IO[str]):
7-
softspace = ... # type: int
7+
# TODO the typing.IO[] generics should be split into input and output.
88

9-
def __init__(self, s: str = None) -> None: ...
9+
class InputType(IO[str], Iterator[str]):
1010
def getvalue(self) -> str: ...
1111
def close(self) -> None: ...
1212
@property
1313
def closed(self) -> bool: ...
14-
def fileno(self) -> int: ...
1514
def flush(self) -> None: ...
1615
def isatty(self) -> bool: ...
1716
def read(self, size: int = -1) -> str: ...
18-
def readable(self) -> bool: ...
1917
def readline(self, size: int = -1) -> str: ...
2018
def readlines(self, hint: int = -1) -> List[str]: ...
2119
def seek(self, offset: int, whence: int = ...) -> None: ...
22-
def seekable(self) -> bool: ...
2320
def tell(self) -> int: ...
24-
def truncate(self, size: int = None) -> int:
25-
raise IOError()
26-
def writable(self) -> bool: ...
27-
def __next__(self) -> str: ...
28-
def __enter__(self) -> Any: ...
29-
def __exit__(self, exc_type: type, exc_val: Any, exc_tb: Any) -> Any: ...
30-
# The C extension actually returns an "InputType".
31-
def __iter__(self) -> Iterator[str]: ...
32-
# only StringO:
21+
def truncate(self, size: int = ...) -> Optional[int]: ...
22+
def __iter__(self) -> 'InputType': ...
23+
def next(self) -> str: ...
24+
def reset(self) -> None: ...
25+
26+
class OutputType(IO[str], Iterator[str]):
27+
@property
28+
def softspace(self) -> int: ...
29+
def getvalue(self) -> str: ...
30+
def close(self) -> None: ...
31+
@property
32+
def closed(self) -> bool: ...
33+
def flush(self) -> None: ...
34+
def isatty(self) -> bool: ...
35+
def read(self, size: int = -1) -> str: ...
36+
def readline(self, size: int = -1) -> str: ...
37+
def readlines(self, hint: int = -1) -> List[str]: ...
38+
def seek(self, offset: int, whence: int = ...) -> None: ...
39+
def tell(self) -> int: ...
40+
def truncate(self, size: int = ...) -> Optional[int]: ...
41+
def __iter__(self) -> 'OutputType': ...
42+
def next(self) -> str: ...
3343
def reset(self) -> None: ...
3444
def write(self, b: Union[str, unicode]) -> None: ...
3545
def writelines(self, lines: Iterable[Union[str, unicode]]) -> None: ...
3646

37-
InputType = StringIO
38-
OutputType = StringIO
47+
@overload
48+
def StringIO() -> OutputType: ...
49+
@overload
50+
def StringIO(s: str) -> InputType: ...

builtins/2.7/select.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Stubs for the 'select' module."""
22

3-
from typing import Any, Optional, Tuple, Iterable
3+
from typing import Any, Optional, Tuple, Iterable, List
44

55
EPOLLERR = ... # type: int
66
EPOLLET = ... # type: int

builtins/2.7/signal.pyi

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from typing import Callable, Any, Tuple, Union
2+
from types import FrameType
23

3-
SIG_DFL = ... # type: long
4-
SIG_IGN = ... # type: long
5-
ITIMER_REAL = ... # type: long
6-
ITIMER_VIRTUAL = ... # type: long
7-
ITIMER_PROF = ... # type: long
4+
SIG_DFL = ... # type: int
5+
SIG_IGN = ... # type: int
6+
ITIMER_REAL = ... # type: int
7+
ITIMER_VIRTUAL = ... # type: int
8+
ITIMER_PROF = ... # type: int
89

910
SIGABRT = ... # type: int
1011
SIGALRM = ... # type: int
@@ -43,24 +44,19 @@ SIGXCPU = ... # type: int
4344
SIGXFSZ = ... # type: int
4445
NSIG = ... # type: int
4546

46-
# Python 3 only:
47-
CTRL_C_EVENT = 0
48-
CTRL_BREAK_EVENT = 0
49-
GSIG = 0
50-
5147
class ItimerError(IOError): ...
5248

53-
_HANDLER = Union[Callable[[int, Any], Any], int, None]
49+
_HANDLER = Union[Callable[[int, FrameType], None], int, None]
5450

5551
def alarm(time: int) -> int: ...
5652
def getsignal(signalnum: int) -> _HANDLER: ...
5753
def pause() -> None: ...
5854
def setitimer(which: int, seconds: float, interval: float = None) -> Tuple[float, float]: ...
5955
def getitimer(which: int) -> Tuple[float, float]: ...
60-
def set_wakeup_fd(fd: int) -> long: ...
56+
def set_wakeup_fd(fd: int) -> int: ...
6157
def siginterrupt(signalnum: int, flag: bool) -> None:
6258
raise RuntimeError()
63-
def signal(signalnum: int, handler: _HANDLER) -> None:
59+
def signal(signalnum: int, handler: _HANDLER) -> _HANDLER:
6460
raise RuntimeError()
65-
def default_int_handler(*args, **kwargs) -> Any:
61+
def default_int_handler(signum: int, frame: FrameType) -> None:
6662
raise KeyboardInterrupt()

builtins/2.7/sys.pyi

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Stubs for the 'sys' module."""
22

33
from typing import (
4-
IO, Union, List, Sequence, Any, Dict, Tuple, BinaryIO, overload
4+
IO, Union, List, Sequence, Any, Dict, Tuple, BinaryIO, Optional, Callable, overload
55
)
6+
from types import FrameType, ModuleType, TracebackType
67

78
class _flags:
89
bytes_warning = ... # type: int
@@ -42,10 +43,10 @@ class _version_info(Tuple[int, int, int, str, int]):
4243
releaselevel = ''
4344
serial = 0
4445

45-
_mercurial = ... # type: tuple
46+
_mercurial = ... # type: Tuple[str, str, str]
4647
api_version = ... # type: int
4748
argv = ... # type: List[str]
48-
builtin_module_names = ... # type: List[str]
49+
builtin_module_names = ... # type: Tuple[str, ...]
4950
byteorder = ... # type: str
5051
copyright = ... # type: str
5152
dont_write_bytecode = ... # type: bool
@@ -58,19 +59,33 @@ long_info = ... # type: object
5859
maxint = ... # type: int
5960
maxsize = ... # type: int
6061
maxunicode = ... # type: int
61-
modules = ... # type: Dict[str, module]
62+
modules = ... # type: Dict[str, ModuleType]
6263
path = ... # type: List[str]
6364
platform = ... # type: str
6465
prefix = ... # type: str
6566
py3kwarning = ... # type: bool
67+
__stderr__ = ... # type: IO[str]
68+
__stdin__ = ... # type: IO[str]
69+
__stdout__ = ... # type: IO[str]
6670
stderr = ... # type: IO[str]
6771
stdin = ... # type: IO[str]
6872
stdout = ... # type: IO[str]
69-
subversion = ... # type: tuple
73+
subversion = ... # type: Tuple[str, str, str]
7074
version = ... # type: str
7175
warnoptions = ... # type: object
7276
float_info = ... # type: _float_info
7377
version_info = ... # type: _version_info
78+
ps1 = ''
79+
ps2 = ''
80+
last_type = ... # type: type
81+
last_value = ... # type: BaseException
82+
last_traceback = ... # type: TracebackType
83+
# TODO precise types
84+
meta_path = ... # type: List[Any]
85+
path_hooks = ... # type: List[Any]
86+
path_importer_cache = ... # type: Dict[str, Any]
87+
displayhook = ... # type: Optional[Callable[[int], None]]
88+
excepthook = ... # type: Optional[Callable[[type, BaseException, TracebackType], None]]
7489

7590
class _WindowsVersionType:
7691
major = ... # type: Any
@@ -83,17 +98,17 @@ class _WindowsVersionType:
8398
suite_mask = ... # type: Any
8499
product_type = ... # type: Any
85100

86-
def getwindowsversion() -> _WindowsVersionType: ... # TODO return type
101+
def getwindowsversion() -> _WindowsVersionType: ...
87102

88103
def _clear_type_cache() -> None: ...
89-
def _current_frames() -> Dict[int, Any]: ...
90-
def _getframe(depth: int = ...) -> Any: ... # TODO: Return FrameObject
104+
def _current_frames() -> Dict[int, FrameType]: ...
105+
def _getframe(depth: int = ...) -> FrameType: ...
91106
def call_tracing(fn: Any, args: Any) -> Any: ...
92-
def displayhook(value: int) -> None: ... # value might be None
93-
def excepthook(type_: type, value: BaseException, traceback: Any) -> None: ... # TODO traceback type
107+
def __displayhook__(value: int) -> None: ...
108+
def __excepthook__(type_: type, value: BaseException, traceback: TracebackType) -> None: ...
94109
def exc_clear() -> None:
95110
raise DeprecationWarning()
96-
def exc_info() -> Tuple[type, Any, Any]: ... # TODO traceback type
111+
def exc_info() -> Tuple[type, BaseException, TracebackType]: ...
97112
def exit(arg: int = ...) -> None:
98113
raise SystemExit()
99114
def getcheckinterval() -> int: ... # deprecated

0 commit comments

Comments
 (0)