various fixes to asyncio stubs (#1305)

This commit is contained in:
Jelle Zijlstra
2017-05-23 16:14:29 -07:00
committed by Matthias Kramm
parent 0bda8c0cef
commit 6c5474ae8c
12 changed files with 51 additions and 41 deletions

View File

@@ -1,8 +1,5 @@
"""The asyncio package, tracking PEP 3156."""
import socket
import sys
from typing import Type
from typing import List, Type
from asyncio.coroutines import (
coroutine as coroutine,
@@ -49,7 +46,7 @@ from asyncio.tasks import (
ALL_COMPLETED as ALL_COMPLETED,
as_completed as as_completed,
ensure_future as ensure_future,
ensure_future as async,
async as async,
gather as gather,
run_coroutine_threadsafe as run_coroutine_threadsafe,
shield as shield,
@@ -63,6 +60,7 @@ from asyncio.events import (
AbstractEventLoop as AbstractEventLoop,
AbstractServer as AbstractServer,
Handle as Handle,
TimerHandle as TimerHandle,
get_event_loop_policy as get_event_loop_policy,
set_event_loop_policy as set_event_loop_policy,
get_event_loop as get_event_loop,
@@ -88,6 +86,12 @@ from asyncio.locks import (
if sys.version_info < (3, 5):
from asyncio.queues import JoinableQueue as JoinableQueue
else:
from asyncio.futures import isfuture as isfuture
from asyncio.events import (
_set_running_loop as _set_running_loop,
_get_running_loop as _get_running_loop,
)
if sys.platform != 'win32':
from asyncio.streams import (
open_unix_connection as open_unix_connection,
@@ -104,4 +108,4 @@ DefaultEventLoopPolicy = ... # type: Type[AbstractEventLoopPolicy]
# TODO: AbstractChildWatcher (UNIX only)
__all__ = ... # type: str
__all__: List[str]

View File

@@ -1,6 +1,6 @@
from typing import Any, Callable, Generator, TypeVar
from typing import Any, Callable, Generator, List, TypeVar
__all__ = ... # type: str
__all__: List[str]
_F = TypeVar('_F', bound=Callable[..., Any])

View File

@@ -9,7 +9,7 @@ from asyncio.protocols import BaseProtocol
from asyncio.tasks import Task
from asyncio.transports import BaseTransport
__all__ = ... # type: str
__all__: List[str]
_T = TypeVar('_T')
_Context = Dict[str, Any]
@@ -18,11 +18,6 @@ _ProtocolFactory = Callable[[], BaseProtocol]
_SSLContext = Union[bool, None, ssl.SSLContext]
_TransProtPair = Tuple[BaseTransport, BaseProtocol]
PIPE = ... # type: Any # from subprocess.PIPE
AF_UNSPEC = 0 # from socket
AI_PASSIVE = 0
class Handle:
_cancelled = False
_args = ... # type: List[Any]
@@ -32,6 +27,11 @@ class Handle:
def cancel(self) -> None: ...
def _run(self) -> None: ...
class TimerHandle(Handle):
def __init__(self, when: float, callback: Callable[..., Any], args: List[Any],
loop: AbstractEventLoop) -> None: ...
def __hash__(self) -> int: ...
class AbstractServer:
def close(self) -> None: ...
@coroutine
@@ -218,3 +218,6 @@ def new_event_loop() -> AbstractEventLoop: ...
def get_child_watcher() -> Any: ... # TODO: unix_events.AbstractChildWatcher
def set_child_watcher(watcher: Any) -> None: ... # TODO: unix_events.AbstractChildWatcher
def _set_running_loop(loop: AbstractEventLoop) -> None: ...
def _get_running_loop() -> AbstractEventLoop: ...

View File

@@ -1,15 +1,14 @@
import sys
from typing import Any, Union, Callable, TypeVar, List, Generic, Iterable, Generator, Awaitable
from .events import AbstractEventLoop
from concurrent.futures._base import (
Error as Error,
)
from concurrent.futures import (
CancelledError as CancelledError,
TimeoutError as TimeoutError,
Future as ConcurrentFuture,
Future as _ConcurrentFuture,
Error,
)
__all__ = ... # type: str
__all__: List[str]
_T = TypeVar('_T')
@@ -23,6 +22,9 @@ class _TracebackLogger:
def clear(self) -> None: ...
def __del__(self) -> None: ...
if sys.version_info >= (3, 5):
def isfuture(obj: object) -> bool: ...
class Future(Iterable[_T], Awaitable[_T], Generic[_T]):
_state = ... # type: str
_exception = ... # type: BaseException
@@ -46,4 +48,4 @@ class Future(Iterable[_T], Awaitable[_T], Generic[_T]):
def __iter__(self) -> Generator[Any, None, _T]: ...
def __await__(self) -> Generator[Any, None, _T]: ...
def wrap_future(f: Union[ConcurrentFuture[_T], Future[_T]]) -> Future[_T]: ...
def wrap_future(f: Union[_ConcurrentFuture[_T], Future[_T]]) -> Future[_T]: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Callable, Generator, Iterable, Iterator, TypeVar, Union, Optional
from typing import Any, Callable, Generator, Iterable, Iterator, List, TypeVar, Union, Optional
from .coroutines import coroutine
from .events import AbstractEventLoop
@@ -6,7 +6,7 @@ from .futures import Future
_T = TypeVar('_T')
__all__ = ... # type: str
__all__: List[str]
class _ContextManager:
def __init__(self, lock: Union[Lock, Semaphore]) -> None: ...

View File

@@ -1,7 +1,7 @@
from asyncio import transports
from typing import AnyStr
from typing import AnyStr, List
__all__ = ... # type: str
__all__: List[str]
class BaseProtocol:

View File

@@ -2,9 +2,9 @@ import sys
from asyncio.events import AbstractEventLoop
from .coroutines import coroutine
from .futures import Future
from typing import Any, Generator, Generic, TypeVar
from typing import Any, Generator, Generic, List, TypeVar
__all__ = ... # type: str
__all__: List[str]
class QueueEmpty(Exception): ...

View File

@@ -1,15 +1,15 @@
import sys
from typing import Any, Awaitable, Callable, Generator, Iterable, Optional, Tuple
from typing import Any, Awaitable, Callable, Generator, Iterable, List, Optional, Tuple
from . import coroutines
from . import events
from . import protocols
from . import transports
ClientConnectedCallback = Callable[[StreamReader, StreamWriter], Optional[Awaitable[None]]]
_ClientConnectedCallback = Callable[[StreamReader, StreamWriter], Optional[Awaitable[None]]]
__all__ = ... # type: str
__all__: List[str]
class IncompleteReadError(EOFError):
def __init__(self, partial: str, expected: int) -> None: ...
@@ -29,7 +29,7 @@ def open_connection(
@coroutines.coroutine
def start_server(
client_connected_cb: ClientConnectedCallback,
client_connected_cb: _ClientConnectedCallback,
host: str = ...,
port: int = ...,
*,
@@ -50,7 +50,7 @@ if sys.platform != 'win32':
@coroutines.coroutine
def start_unix_server(
client_connected_cb: ClientConnectedCallback,
client_connected_cb: _ClientConnectedCallback,
path: str = ...,
*,
loop: int = ...,
@@ -62,7 +62,7 @@ class FlowControlMixin(protocols.Protocol): ...
class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
def __init__(self,
stream_reader: StreamReader,
client_connected_cb: ClientConnectedCallback = ...,
client_connected_cb: _ClientConnectedCallback = ...,
loop: events.AbstractEventLoop = ...) -> None: ...
def connection_made(self, transport: transports.BaseTransport) -> None: ...
def connection_lost(self, exc: Exception) -> None: ...
@@ -99,8 +99,8 @@ class StreamReader:
@coroutines.coroutine
def readline(self) -> Generator[Any, None, bytes]: ...
@coroutines.coroutine
def readuntil(self, separator=b'\n') -> Generator[Any, None, bytes]: ...
def readuntil(self, separator: bytes = ...) -> Generator[Any, None, bytes]: ...
@coroutines.coroutine
def read(self, n=-1) -> Generator[Any, None, bytes]: ...
def read(self, n: int = ...) -> Generator[Any, None, bytes]: ...
@coroutines.coroutine
def readexactly(self, n) -> Generator[Any, None, bytes]: ...

View File

@@ -3,9 +3,9 @@ from asyncio import protocols
from asyncio import streams
from asyncio import transports
from asyncio.coroutines import coroutine
from typing import Any, AnyStr, Generator, Optional, Tuple, Union
from typing import Any, AnyStr, Generator, List, Optional, Tuple, Union
__all__ = ... # type: str
__all__: List[str]
PIPE = ... # type: int
STDOUT = ... # type: int

View File

@@ -5,7 +5,7 @@ import concurrent.futures
from .events import AbstractEventLoop
from .futures import Future
__all__ = ... # type: str
__all__: List[str]
_T = TypeVar('_T')
_FutureT = Union[Future[_T], Generator[Any, None, _T], Awaitable[_T]]
@@ -18,6 +18,7 @@ def as_completed(fs: Sequence[_FutureT[_T]], *, loop: AbstractEventLoop = ...,
timeout: Optional[float] = ...) -> Iterator[Generator[Any, None, _T]]: ...
def ensure_future(coro_or_future: _FutureT[_T],
*, loop: AbstractEventLoop = ...) -> Future[_T]: ...
async = ensure_future
# TODO: gather() should use variadic type vars instead of _TAny.
_TAny = Any
def gather(*coros_or_futures: _FutureT[_TAny],

View File

@@ -1,6 +1,6 @@
from typing import Dict, Any, TypeVar, Mapping, List
__all__ = ... # type: str
__all__: List[str]
class BaseTransport:
def __init__(self, extra: Mapping[Any, Any] = ...) -> None: ...

View File

@@ -25,7 +25,7 @@ class Future(Generic[_T]):
def cancelled(self) -> bool: ...
def running(self) -> bool: ...
def done(self) -> bool: ...
def add_done_callback(self, fn: Callable[[Future], Any]) -> None: ...
def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ...
def result(self, timeout: Optional[float] = ...) -> _T: ...
def exception(self, timeout: Optional[float] = ...) -> Optional[BaseException]: ...
def set_running_or_notify_cancel(self) -> None: ...
@@ -39,6 +39,6 @@ class Executor:
def __enter__(self) -> Executor: ...
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ...
def as_completed(fs: Iterable[Future], timeout: Optional[float] = ...) -> Iterator[Future]: ...
def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ...
def wait(fs: Iterable[Future], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future], Set[Future]]: ...
def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ...