8000 various fixes to asyncio stubs (#1305) · python/typeshed@6c5474a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c5474a

Browse files
JelleZijlstramatthiaskramm
authored andcommitted
various fixes to asyncio stubs (#1305)
1 parent 0bda8c0 commit 6c5474a

File tree

12 files changed

+51
-41
lines changed

12 files changed

+51
-41
lines changed

stdlib/3.4/asyncio/__init__.pyi

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
"""The asyncio package, tracking PEP 3156."""
2-
3-
import socket
41
import sys
5-
from typing import Type
2+
from typing import List, Type
63

74
from asyncio.coroutines import (
85
coroutine as coroutine,
@@ -49,7 +46,7 @@ from asyncio.tasks import (
4946
ALL_COMPLETED as ALL_COMPLETED,
5047
as_completed as as_completed,
5148
ensure_future as ensure_future,
52-
ensure_future as async,
49+
async as async,
5350
gather as gather,
5451
run_coroutine_threadsafe as run_coroutine_threadsafe,
5552
shield as shield,
@@ -63,6 +60,7 @@ from asyncio.events import (
6360
AbstractEventLoop as AbstractEventLoop,
6461
AbstractServer as AbstractServer,
6562
Handle as Handle,
63+
TimerHandle as TimerHandle,
6664
get_event_loop_policy as get_event_loop_policy,
6765
set_event_loop_policy as set_event_loop_policy,
6866
get_event_loop as get_event_loop,
@@ -88,6 +86,12 @@ from asyncio.locks import (
8886

8987
if sys.version_info < (3, 5):
9088
from asyncio.queues import JoinableQueue as JoinableQueue
89+
else:
90+
from asyncio.futures import isfuture as isfuture
91+
from asyncio.events import (
92+
_set_running_loop as _set_running_loop,
93+
_get_running_loop as _get_running_loop,
94+
)
9195
if sys.platform != 'win32':
9296
from asyncio.streams import (
9397
open_unix_connection as open_unix_connection,
@@ -104,4 +108,4 @@ DefaultEventLoopPolicy = ... # type: Type[AbstractEventLoopPolicy]
104108

105109
# TODO: AbstractChildWatcher (UNIX only)
106110

107-
__all__ = ... # type: str
111+
__all__: List[str]

stdlib/3.4/asyncio/coroutines.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from typing import Any, Callable, Generator, TypeVar
1+
from typing import Any, Callable, Generator, List, TypeVar
22

3-
__all__ = ... # type: str
3+
__all__: List[str]
44

55
_F = TypeVar('_F', bound=Callable[..., Any])
66

stdlib/3.4/asyncio/events.pyi

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from asyncio.protocols import BaseProtocol
99
from asyncio.tasks import Task
1010
from asyncio.transports import BaseTransport
1111

12-
__all__ = ... # type: str
12+
__all__: List[str]
1313

1414
_T = TypeVar('_T')
1515
_Context = Dict[str, Any]
@@ -18,11 +18,6 @@ _ProtocolFactory = Callable[[], BaseProtocol]
1818
_SSLContext = Union[bool, None, ssl.SSLContext]
1919
_TransProtPair = Tuple[BaseTransport, BaseProtocol]
2020

21-
PIPE = ... # type: Any # from subprocess.PIPE
22-
23-
AF_UNSPEC = 0 # from socket
24-
AI_PASSIVE = 0
25-
2621
class Handle:
2722
_cancelled = False
2823
_args = ... # type: List[Any]
@@ -32,6 +27,11 @@ class Handle:
3227
def cancel(self) -> None: ...
3328
def _run(self) -> None: ...
3429

30+
class TimerHandle(Handle):
31+
def __init__(self, when: float, callback: Callable[..., Any], args: List[Any],
32+
loop: AbstractEventLoop) -> None: ...
33+
def __hash__(self) -> int: ...
34+
3535
class AbstractServer:
3636
def close(self) -> None: ...
3737
@coroutine
@@ -218,3 +218,6 @@ def new_event_loop() -> AbstractEventLoop: ...
218218

219219
def get_child_watcher() -> Any: ... # TODO: unix_events.AbstractChildWatcher
220220
def set_child_watcher(watcher: Any) -> None: ... # TODO: unix_events.AbstractChildWatcher
221+
222+
def _set_running_loop(loop: AbstractEventLoop) -> None: ...
223+
def _get_running_loop() -> AbstractEventLoop: ...

stdlib/3.4/asyncio/futures.pyi

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
import sys
12
from typing import Any, Union, Callable, TypeVar, List, Generic, Iterable, Generator, Awaitable
23
from .events import AbstractEventLoop
3-
from concurrent.futures._base import (
4-
Error as Error,
5-
)
64
from concurrent.futures import (
75
CancelledError as CancelledError,
86
TimeoutError as TimeoutError,
9-
Future as ConcurrentFuture,
7+
Future as _ConcurrentFuture,
8+
Error,
109
)
1110

12-
__all__ = ... # type: str
11+
__all__: List[str]
1312

1413
_T = TypeVar('_T')
1514

@@ -23,6 +22,9 @@ class _TracebackLogger:
2322
def clear(self) -> None: ...
2423
def __del__(self) -> None: ...
2524

25+
if sys.version_info >= (3, 5):
26+
def isfuture(obj: object) -> bool: ...
27+
2628
class Future(Iterable[_T], Awaitable[_T], Generic[_T]):
2729
_state = ... # type: str
2830
_exception = ... # type: BaseException
@@ -46,4 +48,4 @@ class Future(Iterable[_T], Awaitable[_T], Generic[_T]):
4648
def __iter__(self) -> Generator[Any, None, _T]: ...
4749
def __await__(self) -> Generator[Any, None, _T]: ...
4850

49-
def wrap_future(f: Union[ConcurrentFuture[_T], Future[_T]]) -> Future[_T]: ...
51+
def wrap_future(f: Union[_ConcurrentFuture[_T], Future[_T]]) -> Future[_T]: ...

stdlib/3.4/asyncio/locks.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from typing import Any, Callable, Generator, Iterable, Iterator, TypeVar, Union, Optional
1+
from typing import Any, Callable, Generator, Iterable, Iterator, List, TypeVar, Union, Optional
22

33
from .coroutines import coroutine
44
from .events import AbstractEventLoop
55
from .futures import Future
66

77
_T = TypeVar('_T')
88

9-
__all__ = ... # type: str
9+
__all__: List[str]
1010

1111
class _ContextManager:
1212
def __init__(self, lock: Union[Lock, Semaphore]) -> None: ...

stdlib/3.4/asyncio/protocols.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from asyncio import transports
2-
from typing import AnyStr
2+
from typing import AnyStr, List
33

4-
__all__ = ... # type: str
4+
__all__: List[str]
55

66

77
class BaseProtocol:

stdlib/3.4/asyncio/queues.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import sys
22
from asyncio.events import AbstractEventLoop
33
from .coroutines import coroutine
44
from .futures import Future
5-
from typing import Any, Generator, Generic, TypeVar
5+
from typing import Any, Generator, Generic, List, TypeVar
66

7-
__all__ = ... # type: str
7+
__all__: List[str]
88

99

1010
class QueueEmpty(Exception): ...

stdlib/3.4/asyncio/streams.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import sys
2-
from typing import Any, Awaitable, Callable, Generator, Iterable, Optional, Tuple
2+
from typing import Any, Awaitable, Callable, Generator, Iterable, List, Optional, Tuple
33

44
from . import coroutines
55
from . import events
66
from . import protocols
77
from . import transports
88

9-
ClientConnectedCallback = Callable[[StreamReader, StreamWriter], Optional[Awaitable[None]]]
9+
_ClientConnectedCallback = Callable[[StreamReader, StreamWriter], Optional[Awaitable[None]]]
1010

1111

12-
__all__ = ... # type: str
12+
__all__: List[str]
1313

1414
class IncompleteReadError(EOFError):
1515
def __init__(self, partial: str, expected: int) -> None: ...
@@ -29,7 +29,7 @@ def open_connection(
2929

3030
@coroutines.coroutine
3131
def start_server(
32-
client_connected_cb: ClientConnectedCallback,
32+
client_connected_cb: _ClientConnectedCallback,
3333
host: str = ...,
3434
port: int = ...,
3535
*,
@@ -50,7 +50,7 @@ if sys.platform != 'win32':
5050

5151
@coroutines.coroutine
5252
def start_unix_server(
53-
client_connected_cb: ClientConnectedCallback,
53+
client_connected_cb: _ClientConnectedCallback,
5454
path: str = ...,
5555
*,
5656
loop: int = ...,
@@ -62,7 +62,7 @@ class FlowControlMixin(protocols.Protocol): ...
6262
class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
6363
def __init__(self,
6464
stream_reader: StreamReader,
65-
client_connected_cb: ClientConnectedCallback = ...,
65+
client_connected_cb: _ClientConnectedCallback = ...,
6666
loop: events.AbstractEventLoop = ...) -> None: ...
6767
def connection_made(self, transport: transports.BaseTransport) -> None: ...
6868
def connection_lost(self, exc: Exception) -> None: ...
@@ -99,8 +99,8 @@ class StreamReader:
9999
@coroutines.coroutine
100100
def readline(self) -> Generator[Any, None, bytes]: ...
101101
@coroutines.coroutine
102-
def readuntil(self, separator=b'\n') -> Generator[Any, None, bytes]: ...
102+
def readuntil(self, separator: bytes = ...) -> Generator[Any, None, bytes]: ...
103103
@coroutines.coroutine
104-
def read(self, n=-1) -> Generator[Any, None, bytes]: ...
104+
def read(self, n: int = ...) -> Generator[Any, None, bytes]: ...
105105
@coroutines.coroutine
106106
def readexactly(self, n) -> Generator[Any, None, bytes]: ...

stdlib/3.4/asyncio/subprocess.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ from asyncio import protocols
33
from asyncio import streams
44
from asyncio import transports
55
from asyncio.coroutines import coroutine
6-
from typing import Any, AnyStr, Generator, Optional, Tuple, Union
6+
from typing import Any, AnyStr, Generator, List, Optional, Tuple, Union
77

8-
__all__ = ... # type: str
8+
__all__: List[str]
99

1010
PIPE = ... # type: int
1111
STDOUT = ... # type: int

stdlib/3.4/asyncio/tasks.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import concurrent.futures
55
from .events import AbstractEventLoop
66
from .futures import Future
77

8-
__all__ = ... # type: str
8+
__all__: List[str]
99

1010
_T = TypeVar('_T')
1111
_FutureT = Union[Future[_T], Generator[Any, None, _T], Awaitable[_T]]
@@ -18,6 +18,7 @@ def as_completed(fs: Sequence[_FutureT[_T]], *, loop: AbstractEventLoop = ...,
1818
timeout: Optional[float] = ...) -> Iterator[Generator[Any, None, _T]]: ...
1919
def ensure_future(coro_or_future: _FutureT[_T],
2020
*, loop: AbstractEventLoop = ...) -> Future[_T]: ...
21+
async = ensure_future
2122
# TODO: gather() should use variadic type vars instead of _TAny.
2223
_TAny = Any
2324
def gather(*coros_or_futures: _FutureT[_TAny],

stdlib/3.4/asyncio/transports.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Dict, Any, TypeVar, Mapping, List
22

3-
__all__ = ... # type: str
3+
__all__: List[str]
44

55
class BaseTransport:
66
def __init__(self, extra: Mapping[Any, Any] = ...) -> None: ...

stdlib/3/concurrent/futures/_base.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Future(Generic[_T]):
2525
def cancelled(self) -> bool: ...
2626
def running(self) -> bool: ...
2727
def done(self) -> bool: ...
28-
def add_done_callback(self, fn: Callable[[Future], Any]) -> None: ...
28+
def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ...
2929
def result(self, timeout: Optional[float] = ...) -> _T: ...
3030
def exception(self, timeout: Optional[float] = ...) -> Optional[BaseException]: ...
3131
def set_running_or_notify_cancel(self) -> None: ...
@@ -39,6 +39,6 @@ class Executor:
3939
def __enter__(self) -> Executor: ...
4040
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ...
4141

42-
def as_completed(fs: Iterable[Future], timeout: Optional[float] = ...) -> Iterator[Future]: ...
42+
def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ...
4343

44-
def wait(fs: Iterable[Future], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future], Set[Future]]: ...
44+
def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ...

0 commit comments

Comments
 (0)
0