Skip to content

Commit 96b5c6b

Browse files
author
Max Rozentsveyg
committed
fixes
1 parent a3e45b5 commit 96b5c6b

File tree

10 files changed

+232
-299
lines changed

10 files changed

+232
-299
lines changed

stdlib/3.4/asyncio/tasks.pyi

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ from .futures import Future
88
__all__: List[str]
99

1010
_T = TypeVar('_T')
11+
_T1 = TypeVar('_T1')
12+
_T2 = TypeVar('_T2')
13+
_T3 = TypeVar('_T3')
14+
_T4 = TypeVar('_T4')
15+
_T5 = TypeVar('_T5')
1116
_FutureT = Union[Future[_T], Generator[Any, None, _T], Awaitable[_T]]
1217

1318
FIRST_EXCEPTION = 'FIRST_EXCEPTION'
@@ -19,10 +24,25 @@ def as_completed(fs: Sequence[_FutureT[_T]], *, loop: AbstractEventLoop = ...,
1924
def ensure_future(coro_or_future: _FutureT[_T],
2025
*, loop: AbstractEventLoop = ...) -> Future[_T]: ...
2126
async = ensure_future
22-
# TODO: gather() should use variadic type vars instead of _TAny.
23-
_TAny = Any
24-
def gather(*coros_or_futures: _FutureT[_TAny],
25-
loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[List[_TAny]]: ...
27+
@overload
28+
def gather(coro_or_future1: _FutureT[_T1],
29+
*, loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[Tuple[_T1]]: ...
30+
@overload
31+
def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2],
32+
*, loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[Tuple[_T1, _T2]]: ...
33+
@overload
34+
def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3],
35+
coro_or_future4: _FutureT[_T4],
36+
*, loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[Tuple[_T1, _T2, _T3, _T4]]: ...
37+
@overload
38+
def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3],
39+
coro_or_future4: _FutureT[_T4], coro_or_future5: _FutureT[_T5],
40+
*, loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
41+
@overload
42+
def gather(coro_or_future1: _FutureT[Any], coro_or_future2: _FutureT[Any], coro_or_future3: _FutureT[Any],
43+
coro_or_future4: _FutureT[Any], coro_or_future5: _FutureT[Any], coro_or_future6: _FutureT[Any],
44+
*coros_or_futures: _FutureT[Any],
45+
loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[Tuple[Any, ...]]: ...
2646
def run_coroutine_threadsafe(coro: _FutureT[_T],
2747
loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
2848
def shield(arg: _FutureT[_T], *, loop: AbstractEventLoop = ...) -> Future[_T]: ...

stdlib/3/fcntl.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stubs for fcntl
2+
from io import IOBase
23
from typing import Any, IO, Union
3-
import typing
44

55
FASYNC = ... # type: int
66
FD_CLOEXEC = ... # type: int
@@ -75,7 +75,7 @@ LOCK_SH = ... # type: int
7575
LOCK_UN = ... # type: int
7676
LOCK_WRITE = ... # type: int
7777

78-
_AnyFile = Union[int, IO[Any]]
78+
_AnyFile = Union[int, IO[Any], IOBase]
7979

8080
# TODO All these return either int or bytes depending on the value of
8181
# cmd (not on the type of arg).

stdlib/3/multiprocessing/__init__.pyi

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Stubs for multiprocessing
22

3-
from typing import Any, Callable, Iterable, Mapping, Optional, Dict, List, Union, TypeVar
3+
from typing import (
4+
Any, Callable, ContextManager, Iterable, Mapping, Optional, Dict, List,
5+
Union, TypeVar,
6+
)
47

58
from logging import Logger
9+
from multiprocessing import pool
610
from multiprocessing.context import BaseContext
711
from multiprocessing.managers import SyncManager
812
from multiprocessing.pool import AsyncResult
@@ -12,11 +16,9 @@ import queue
1216

1317
_T = TypeVar('_T')
1418

15-
class Lock():
19+
class Lock(ContextManager[Lock]):
1620
def acquire(self, block: bool = ..., timeout: int = ...) -> None: ...
1721
def release(self) -> None: ...
18-
def __enter__(self) -> 'Lock': ...
19-
def __exit__(self, exc_type, exc_value, tb) -> None: ...
2022

2123
class Event(object):
2224
def __init__(self, *, ctx: BaseContext) -> None: ...
@@ -25,54 +27,13 @@ class Event(object):
2527
def clear(self) -> None: ...
2628
def wait(self, timeout: Optional[int] = ...) -> bool: ...
2729

28-
class Pool():
29-
def __init__(self, processes: Optional[int] = ...,
30-
initializer: Optional[Callable[..., None]] = ...,
31-
initargs: Iterable[Any] = ...,
32-
maxtasksperchild: Optional[int] = ...,
33-
context: Optional[Any] = None) -> None: ...
34-
def apply(self,
35-
func: Callable[..., Any],
36-
args: Iterable[Any] = ...,
37-
kwds: Dict[str, Any]=...) -> Any: ...
38-
def apply_async(self,
39-
func: Callable[..., Any],
40-
args: Iterable[Any] = ...,
41-
kwds: Dict[str, Any] = ...,
42-
callback: Optional[Callable[..., None]] = None,
43-
error_callback: Optional[Callable[[BaseException], None]] = None) -> AsyncResult: ...
44-
def map(self,
45-
func: Callable[..., Any],
46-
iterable: Iterable[Any] = ...,
47-
chunksize: Optional[int] = ...) -> List[Any]: ...
48-
def map_async(self, func: Callable[..., Any],
49-
iterable: Iterable[Any] = ...,
50-
chunksize: Optional[int] = ...,
51-
callback: Optional[Callable[..., None]] = None,
52-
error_callback: Optional[Callable[[BaseException], None]] = None) -> AsyncResult: ...
53-
def imap(self,
54-
func: Callable[..., Any],
55-
iterable: Iterable[Any] = ...,
56-
chunksize: Optional[int] = None) -> Iterable[Any]: ...
57-
def imap_unordered(self,
58-
func: Callable[..., Any],
59-
iterable: Iterable[Any] = ...,
60-
chunksize: Optional[int] = None) -> Iterable[Any]: ...
61-
def starmap(self,
62-
func: Callable[..., Any],
63-
iterable: Iterable[Iterable[Any]] = ...,
64-
chunksize: Optional[int] = None) -> List[Any]: ...
65-
def starmap_async(self,
66-
func: Callable[..., Any],
67-
iterable: Iterable[Iterable[Any]] = ...,
68-
chunksize: Optional[int] = ...,
69-
callback: Optional[Callable[..., None]] = None,
70-
error_callback: Optional[Callable[[BaseException], None]] = None) -> AsyncResult: ...
71-
def close(self) -> None: ...
72-
def terminate(self) -> None: ...
73-
def join(self) -> None: ...
74-
def __enter__(self) -> 'Pool': ...
75-
def __exit__(self, exc_type, exc_val, exc_tb) -> None: ...
30+
# N.B. This is generated at runtime by partially applying
31+
# multiprocessing.context.BaseContext.Pool, so the two signatures should be
32+
# identical (modulo self).
33+
def Pool(processes: Optional[int] = ...,
34+
initializer: Optional[Callable[..., Any]] = ...,
35+
initargs: Iterable[Any] = ...,
36+
maxtasksperchild: Optional[int] = ...) -> pool.Pool: ...
7637

7738
class Process():
7839
name: str

stdlib/3/multiprocessing/context.pyi

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from logging import Logger
44
import multiprocessing
55
import sys
6-
from typing import Any, Callable, Optional, List, Sequence, Tuple, Type, Union
6+
from typing import (
7+
Any, Callable, Iterable, Optional, List, Sequence, Tuple, Type, Union,
8+
)
79

810
class ProcessError(Exception): ...
911

@@ -49,13 +51,16 @@ class BaseContext(object):
4951
def JoinableQueue(self, maxsize: int = ...) -> Any: ...
5052
# TODO: change return to SimpleQueue once a stub exists in multiprocessing.queues
5153
def SimpleQueue(self) -> Any: ...
54+
# N.B. This method is partially applied at runtime to generate
55+
# multiprocessing.Pool, so the two signatures should be identical (modulo
56+
# self).
5257
def Pool(
5358
self,
5459
processes: Optional[int] = ...,
5560
initializer: Optional[Callable[..., Any]] = ...,
56-
initargs: Tuple = ...,
61+
initargs: Iterable[Any] = ...,
5762
maxtasksperchild: Optional[int] = ...
58-
) -> multiprocessing.Pool: ...
63+
) -> multiprocessing.pool.Pool: ...
5964
# TODO: typecode_or_type param is a ctype with a base class of _SimpleCData or array.typecode Need to figure out
6065
# how to handle the ctype
6166
# TODO: change return to RawValue once a stub exists in multiprocessing.sharedctypes

stdlib/3/multiprocessing/managers.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import queue
66
import threading
77
from typing import (
8-
Any, Callable, Dict, Iterable, List, Mapping, Optional, Sequence, TypeVar
8+
Any, Callable, ContextManager, Dict, Iterable, List, Mapping, Optional,
9+
Sequence, TypeVar,
910
)
1011

1112
_T = TypeVar('_T')
@@ -16,13 +17,11 @@ class Namespace: ...
1617

1718
_Namespace = Namespace
1819

19-
class BaseManager:
20+
class BaseManager(ContextManager[BaseManager]):
2021
def register(self, typeid: str, callable: Any = ...) -> None: ...
2122
def shutdown(self) -> None: ...
2223
def start(self, initializer: Optional[Callable[..., Any]] = ...,
2324
initargs: Iterable[Any] = ...) -> None: ...
24-
def __enter__(self) -> 'BaseManager': ...
25-
def __exit__(self, exc_type, exc_value, tb) -> None: ...
2625

2726
class SyncManager(BaseManager):
2827
def BoundedSemaphore(self, value: Any = ...) -> threading.BoundedSemaphore: ...

stdlib/3/multiprocessing/pool.pyi

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22

33
# NOTE: These are incomplete!
44

5-
from typing import Any, Callable, Iterable, Mapping, Optional, Dict, List
5+
from typing import (
6+
Any, Callable, ContextManager, Iterable, Mapping, Optional, Dict, List,
7+
TypeVar,
8+
)
9+
10+
_T = TypeVar('_T', bound='Pool')
611

712
class AsyncResult():
813
def get(self, timeout: float = ...) -> Any: ...
914
def wait(self, timeout: float = ...) -> None: ...
1015
def ready(self) -> bool: ...
1116
def successful(self) -> bool: ...
1217

13-
class ThreadPool():
14-
def __init__(self, processes: Optional[int] = None,
15-
initializer: Optional[Callable[..., Any]] = None,
16-
initargs: Iterable[Any] = ...) -> None: ...
18+
class Pool(ContextManager[Pool]):
19+
def __init__(self, processes: Optional[int] = ...,
20+
initializer: Optional[Callable[..., None]] = ...,
21+
initargs: Iterable[Any] = ...,
22+
maxtasksperchild: Optional[int] = ...,
23+
context: Optional[Any] = None) -> None: ...
1724
def apply(self,
1825
func: Callable[..., Any],
1926
args: Iterable[Any] = ...,
@@ -30,7 +37,7 @@ class ThreadPool():
3037
chunksize: Optional[int] = None) -> List[Any]: ...
3138
def map_async(self, func: Callable[..., Any],
3239
iterable: Iterable[Any] = ...,
33-
chunksize: Optional[Optional[int]] = None,
40+
chunksize: Optional[int] = None,
3441
callback: Optional[Callable[..., None]] = None,
3542
error_callback: Optional[Callable[[BaseException], None]] = None) -> AsyncResult: ...
3643
def imap(self,
@@ -54,5 +61,11 @@ class ThreadPool():
5461
def close(self) -> None: ...
5562
def terminate(self) -> None: ...
5663
def join(self) -> None: ...
57-
def __enter__(self) -> 'ThreadPool': ...
58-
def __exit__(self, exc_type, exc_val, exc_tb) -> None: ...
64+
def __enter__(self: _T) -> _T: ...
65+
66+
67+
class ThreadPool(Pool, ContextManager[ThreadPool]):
68+
69+
def __init__(self, processes: Optional[int] = None,
70+
initializer: Optional[Callable[..., Any]] = None,
71+
initargs: Iterable[Any] = ...) -> None: ...

stdlib/3/smtplib.pyi

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
from typing import Any
1+
from email.message import Message as _Message
2+
from typing import (
3+
Any, AnyStr, Dict, Generic, List, Optional, Sequence, Tuple, Union)
4+
5+
_Reply = Tuple[int, bytes]
6+
_SendErrs = Dict[str, _Reply]
27

38
class SMTPException(OSError): ...
49
class SMTPServerDisconnected(SMTPException): ...
510

611
class SMTPResponseException(SMTPException):
7-
smtp_code = ... # type: Any
8-
smtp_error = ... # type: Any
9-
args = ... # type: Any
10-
def __init__(self, code, msg) -> None: ...
12+
smtp_code = ... # type: int
13+
smtp_error = ... # type: Union[bytes, str]
14+
args = ... # type: Union[Tuple[int, Union[bytes, str]], Tuple[int, bytes, str]]
15+
def __init__(self, code: int, msg: Union[bytes, str]) -> None: ...
1116

1217
class SMTPSenderRefused(SMTPResponseException):
13-
smtp_code = ... # type: Any
14-
smtp_error = ... # type: Any
15-
sender = ... # type: Any
16-
args = ... # type: Any
17-
def __init__(self, code, msg, sender) -> None: ...
18+
smtp_code = ... # type: int
19+
smtp_error = ... # type: bytes
20+
sender = ... # type: str
21+
args = ... # type: Tuple[int, bytes, str]
22+
def __init__(self, code: int, msg: bytes, sender: str) -> None: ...
1823

1924
class SMTPRecipientsRefused(SMTPException):
20-
recipients = ... # type: Any
21-
args = ... # type: Any
22-
def __init__(self, recipients) -> None: ...
25+
recipients = ... # type: _SendErrs
26+
args = ... # type: Tuple[_SendErrs]
27+
def __init__(self, recipients: _SendErrs) -> None: ...
2328

2429
class SMTPDataError(SMTPResponseException): ...
2530
class SMTPConnectError(SMTPResponseException): ...
@@ -30,49 +35,53 @@ def quoteaddr(addrstring): ...
3035
def quotedata(data): ...
3136

3237
class SMTP:
33-
debuglevel = ... # type: Any
38+
debuglevel = ... # type: int
3439
file = ... # type: Any
3540
helo_resp = ... # type: Any
3641
ehlo_msg = ... # type: Any
3742
ehlo_resp = ... # type: Any
3843
does_esmtp = ... # type: Any
3944
default_port = ... # type: Any
40-
timeout = ... # type: Any
45+
timeout = ... # type: float
4146
esmtp_features = ... # type: Any
4247
source_address = ... # type: Any
4348
local_hostname = ... # type: Any
44-
def __init__(self, host=..., port=..., local_hostname=..., timeout=...,
45-
source_address=...): ...
49+
def __init__(self, host: str = ..., port: int = ...,
50+
local_hostname: Optional[str] = ..., timeout: float = ...,
51+
source_address: Tuple[str, int] = ...) -> None: ...
4652
def __enter__(self): ...
4753
def __exit__(self, *args): ...
48-
def set_debuglevel(self, debuglevel): ...
54+
def set_debuglevel(self, debuglevel: int) -> None: ...
4955
sock = ... # type: Any
5056
def connect(self, host=..., port=..., source_address=...): ...
5157
def send(self, s): ...
5258
def putcmd(self, cmd, args=...): ...
53-
def getreply(self): ...
59+
def getreply(self) -> _Reply: ...
5460
def docmd(self, cmd, args=...): ...
5561
def helo(self, name=...): ...
5662
def ehlo(self, name=...): ...
5763
def has_extn(self, opt): ...
5864
def help(self, args=...): ...
59-
def rset(self): ...
60-
def noop(self): ...
61-
def mail(self, sender, options=...): ...
62-
def rcpt(self, recip, options=...): ...
65+
def rset(self) -> _Reply: ...
66+
def noop(self) -> _Reply: ...
67+
def mail(self, sender: str, options: Sequence[str] = ...) -> _Reply: ...
68+
def rcpt(self, recip: str, options: Sequence[str] = ...) -> _Reply: ...
6369
def data(self, msg): ...
6470
def verify(self, address): ...
6571
vrfy = ... # type: Any
6672
def expn(self, address): ...
6773
def ehlo_or_helo_if_needed(self): ...
6874
def login(self, user, password): ...
6975
def starttls(self, keyfile=..., certfile=..., context=...): ...
70-
def sendmail(self, from_addr, to_addrs, msg, mail_options=...,
71-
rcpt_options=...): ...
72-
def send_message(self, msg, from_addr=..., to_addrs=..., mail_options=...,
73-
rcpt_options=...): ...
76+
def sendmail(self, from_addr: str, to_addrs: Union[str, Sequence[str]],
77+
msg: Union[bytes, str], mail_options: Sequence[str] = ...,
78+
rcpt_options: List[str] = ...) -> _SendErrs: ...
79+
def send_message(self, msg: _Message, from_addr: Optional[str] = ...,
80+
to_addrs: Optional[Union[str, Sequence[str]]] = ...,
81+
mail_options: List[str] = ...,
82+
rcpt_options: Sequence[str] = ...) -> _SendErrs: ...
7483
def close(self): ...
75-
def quit(self): ...
84+
def quit(self) -> _Reply: ...
7685

7786
class SMTP_SSL(SMTP):
7887
default_port = ... # type: Any
@@ -84,7 +93,9 @@ class SMTP_SSL(SMTP):
8493

8594
class LMTP(SMTP):
8695
ehlo_msg = ... # type: Any
87-
def __init__(self, host=..., port=..., local_hostname=..., source_address=...) -> None: ...
96+
def __init__(self, host: str = ..., port: int = ...,
97+
local_hostname: Optional[str] = ...,
98+
source_address: Optional[Tuple[str, int]] = ...) -> None: ...
8899
sock = ... # type: Any
89100
file = ... # type: Any
90101
def connect(self, host=..., port=..., source_address=...): ...

0 commit comments

Comments
 (0)