Skip to content

various fixes to asyncio stubs #1305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions stdlib/3.4/asyncio/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -104,4 +108,4 @@ DefaultEventLoopPolicy = ... # type: Type[AbstractEventLoopPolicy]

# TODO: AbstractChildWatcher (UNIX only)

__all__ = ... # type: str
__all__: List[str]
4 changes: 2 additions & 2 deletions stdlib/3.4/asyncio/coroutines.pyi
Original file line number Diff line number Diff line change
@@ -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])

Expand Down
15 changes: 9 additions & 6 deletions stdlib/3.4/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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: ...
14 changes: 8 additions & 6 deletions stdlib/3.4/asyncio/futures.pyi
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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
Expand All @@ -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]: ...
4 changes: 2 additions & 2 deletions stdlib/3.4/asyncio/locks.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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
from .futures import Future

_T = TypeVar('_T')

__all__ = ... # type: str
__all__: List[str]

class _ContextManager:
def __init__(self, lock: Union[Lock, Semaphore]) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/3.4/asyncio/protocols.pyi
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions stdlib/3.4/asyncio/queues.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Expand Down
16 changes: 8 additions & 8 deletions stdlib/3.4/asyncio/streams.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand All @@ -29,7 +29,7 @@ def open_connection(

@coroutines.coroutine
def start_server(
client_connected_cb: ClientConnectedCallback,
client_connected_cb: _ClientConnectedCallback,
host: str = ...,
port: int = ...,
*,
Expand All @@ -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 = ...,
Expand All @@ -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: ...
Expand Down Expand Up @@ -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]: ...
4 changes: 2 additions & 2 deletions stdlib/3.4/asyncio/subprocess.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stdlib/3.4/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion stdlib/3.4/asyncio/transports.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/3/concurrent/futures/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand All @@ -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]]]: ...