Merge pull request #81 from dsp/asyncio

Additional type information for asyncio
This commit is contained in:
Guido van Rossum
2016-02-19 21:19:38 -08:00
10 changed files with 286 additions and 12 deletions

View File

@@ -1,9 +1,40 @@
"""The asyncio package, tracking PEP 3156."""
from asyncio.coroutines import (
coroutine as coroutine,
iscoroutinefunction as iscoroutinefunction,
iscoroutine as iscoroutine,
)
from asyncio.protocols import (
BaseProtocol as BaseProtocol,
Protocol as Protocol,
DatagramProtocol as DatagramProtocol,
SubprocessProtocol as SubprocessProtocol,
)
from asyncio.streams import (
StreamReader as StreamReader,
StreamWriter as StreamWriter,
StreamReaderProtocol as StreamReaderProtocol,
open_connection as open_connection,
start_server as start_server,
IncompleteReadError as IncompleteReadError,
LimitOverrunError as LimitOverrunError,
)
from asyncio.subprocess import (
create_subprocess_exec as create_subprocess_exec,
create_subprocess_shell as create_subprocess_shell,
)
from asyncio.transports import (
BaseTransport as BaseTransport,
ReadTransport as ReadTransport,
WriteTransport as WriteTransport,
Transport as Transport,
DatagramTransport as DatagramTransport,
SubprocessTransport as SubprocessTransport,
)
from asyncio.futures import (
Future as Future,
)
from asyncio.tasks import (
coroutine as coroutine,
sleep as sleep,
Task as Task,
FIRST_COMPLETED as FIRST_COMPLETED,
@@ -15,6 +46,7 @@ from asyncio.tasks import (
from asyncio.events import (
AbstractEventLoopPolicy as AbstractEventLoopPolicy,
AbstractEventLoop as AbstractEventLoop,
AbstractServer as AbstractServer,
Handle as Handle,
get_event_loop as get_event_loop,
)
@@ -27,7 +59,12 @@ from asyncio.queues import (
QueueEmpty as QueueEmpty,
)
__all__ = (futures.__all__ +
__all__ = (coroutines.__all__ +
protocols.__all__ +
streams.__all__ +
subprocess.__all__ +
transports.__all__ +
futures.__all__ +
tasks.__all__ +
events.__all__ +
queues.__all__)

View File

@@ -0,0 +1,8 @@
from typing import Callable, Any
__all__ = ['coroutine',
'iscoroutinefunction', 'iscoroutine']
def coroutine(func: Callable[..., Any]) -> Callable[..., Any]: ...
def iscoroutinefunction(func: Callable[..., Any]) -> bool: ...
def iscoroutine(obj: Any) -> bool: ...

View File

@@ -1,6 +1,7 @@
from typing import Any, Awaitable, TypeVar, List, Callable, Tuple, Union, Dict, Generator
from abc import ABCMeta, abstractmethod
from asyncio.futures import Future
from asyncio.coroutines import coroutine
# __all__ = ['AbstractServer',
# 'TimerHandle',
@@ -29,6 +30,10 @@ class Handle:
def cancel(self) -> None: ...
def _run(self) -> None: ...
class AbstractServer:
def close(self) -> None: ...
@coroutine
def wait_closed(self) -> None: ...
class AbstractEventLoop(metaclass=ABCMeta):
@abstractmethod

View File

@@ -1,5 +1,5 @@
from typing import Any, Union, Callable, TypeVar, List, Generic, Iterable, Generator
from asyncio.events import AbstractEventLoop
from .events import AbstractEventLoop
# __all__ = ['CancelledError', 'TimeoutError',
# 'InvalidStateError',
# 'wrap_future',

View File

@@ -0,0 +1,25 @@
from typing import AnyStr
__all__ = ['BaseProtocol', 'Protocol', 'DatagramProtocol',
'SubprocessProtocol']
from asyncio import transports
class BaseProtocol:
def connection_made(self, transport: transports.BaseTransport) -> None: ...
def connection_lost(self, exc: Exception) -> None: ...
def pause_writing(self) -> None: ...
def resume_writing(self) -> None: ...
class Protocol(BaseProtocol):
def data_received(self, data: AnyStr) -> None: ...
def eof_received(self) -> bool: ...
class DatagramProtocol(BaseProtocol):
def datagram_received(self, data: AnyStr, addr: str) -> None: ...
def error_received(self, exc: Exception) -> None: ...
class SubprocessProtocol(BaseProtocol):
def pipe_data_received(self, fd: int, data: AnyStr) -> None: ...
def pipe_connection_lost(self, fd: int, exc: Exception) -> None: ...
def process_exited(self) -> None: ...

View File

@@ -4,7 +4,7 @@ __all__ = ['Queue', 'PriorityQueue', 'LifoQueue', 'JoinableQueue',
'QueueFull', 'QueueEmpty']
from asyncio.events import AbstractEventLoop
from .tasks import coroutine
from .coroutines import coroutine
from .futures import Future

View File

@@ -0,0 +1,104 @@
from typing import Iterable, Tuple, Callable, Any, AnyStr
ClientConnectedCallback = Callable[[Tuple[StreamReader, StreamWriter]], None]
import socket
from . import coroutines
from . import events
from . import protocols
from . import transports
__all__ = ['StreamReader', 'StreamWriter', 'StreamReaderProtocol',
'open_connection', 'start_server',
'IncompleteReadError',
'LimitOverrunError']
class IncompleteReadError(EOFError):
def __init__(self, partial: str, expected: int) -> None: ...
class LimitOverrunError(Exception):
def __init__(self, message: str, consumed: int) -> None: ...
@coroutines.coroutine
def open_connection(
host: str = ...,
port: int = ...,
*,
loop: events.AbstractEventLoop = ...,
limit: int = ...,
**kwds: Any) -> Tuple[StreamReader, StreamWriter]: ...
@coroutines.coroutine
def start_server(
client_connected_cb: ClientConnectedCallback,
host: str = ...,
port: int = ...,
*,
loop: events.AbstractEventLoop = ...,
limit: int = ...,
**kwds: Any) -> events.AbstractServer: ...
if hasattr(socket, 'AF_UNIX'):
@coroutines.coroutine
def open_unix_connection(
path: str = ...,
*,
loop: events.AbstractEventLoop = ...,
limit: int = ...,
**kwds: Any): ...
@coroutines.coroutine
def start_unix_server(
client_connected_cb: ClientConnectedCallback,
path: str = ...,
*,
loop: int = ...,
limit: int = ...,
**kwds: Any) -> events.AbstractServer: ...
class FlowControlMixin(protocols.Protocol): ...
class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
def __init__(self,
stream_reader: StreamReader,
client_connected_cb: ClientConnectedCallback = ...,
loop: events.AbstractEventLoop = ...) -> None: ...
def connection_made(self, transport: transports.BaseTransport) -> None: ...
def connection_lost(self, exc: Exception) -> None: ...
def data_received(self, data: AnyStr) -> None: ...
def eof_received(self) -> bool: ...
class StreamWriter:
def __init__(self,
transport: transports.BaseTransport,
protocol: protocols.BaseProtocol,
reader: StreamReader,
loop: events.AbstractEventLoop) -> None: ...
@property
def transport(self) -> transports.BaseTransport: ...
def write(self, data: AnyStr) -> None: ...
def writelines(self, data: Iterable[str]) -> None: ...
def write_eof(self) -> None: ...
def can_write_eof(self) -> bool: ...
def close(self) -> None: ...
def get_extra_info(self, name: Any, default: Any = ...) -> Any: ...
def drain(self) -> None: ...
class StreamReader:
def __init__(self,
limit: int = ...,
loop: events.AbstractEventLoop = ...) -> None: ...
def exception(self) -> Exception: ...
def set_exception(self, exc: Exception) -> None: ...
def set_transport(self, transport: transports.BaseTransport) -> None: ...
def feed_eof(self) -> None: ...
def at_eof(self) -> bool: ...
def feed_data(self, data: AnyStr): ...
@coroutines.coroutine
def readline(self) -> str: ...
@coroutines.coroutine
def readuntil(self, separator=b'\n') -> str: ...
@coroutines.coroutine
def read(self, n=-1) -> str: ...
@coroutines.coroutine
def readexactly(self, n) -> str: ...

View File

@@ -0,0 +1,60 @@
from typing import Any, AnyStr, Tuple
__all__ = ['create_subprocess_exec', 'create_subprocess_shell']
from asyncio import events
from asyncio import protocols
from asyncio import streams
from asyncio import transports
from asyncio.coroutines import coroutine
PIPE = ... # type: int
STDOUT = ... # type: int
DEVNULL = ... # type: int
class SubprocessStreamProtocol(streams.FlowControlMixin,
protocols.SubprocessProtocol):
def __init__(self, limit: int, loop: events.AbstractEventLoop) -> None: ...
def connection_made(self, transport: transports.BaseTransport) -> None: ...
def pipe_data_received(self, fd: int, data: AnyStr) -> None: ...
def pipe_connection_lost(self, fd: int, exc: Exception): ...
def process_exited(self) -> None: ...
class Process:
def __init__(self,
transport: transports.BaseTransport,
protocol: protocols.BaseProtocol,
loop: events.AbstractEventLoop) -> None: ...
@property
def returncode(self) -> int: ...
@coroutine
def wait(self) -> int: ...
def send_signal(self, signal: int) -> None: ...
def terminatate(self) -> None: ...
def kill(self) -> None: ...
@coroutine
def communicate(self, input: AnyStr = ...) -> Tuple[AnyStr, AnyStr]: ...
@coroutine
def create_subprocess_shell(
*Args: AnyStr,
stdin: int = ...,
stdout: int = ...,
stderr: int = ...,
loop: events.AbstractEventLoop = ...,
limit: int = ...,
**kwds: Any): ...
@coroutine
def create_subprocess_exec(
program: AnyStr,
*args: Any,
stdin: int = ...,
stdout: int = ...,
stderr: int = ...,
loop: events.AbstractEventLoop = ...,
limit: int = ...,
**kwds: Any) -> Process: ...

View File

@@ -1,20 +1,16 @@
from typing import Any, Iterable, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable, Generator
from asyncio.events import AbstractEventLoop
from asyncio.futures import Future
# __all__ = ['iscoroutinefunction', 'iscoroutine',
# 'as_completed', 'async',
# 'gather', 'shield',
# ]
__all__ = ['coroutine', 'Task', 'sleep',
__all__ = ['Task', 'sleep',
'FIRST_COMPLETED', 'FIRST_EXCEPTION', 'ALL_COMPLETED',
'wait', 'wait_for']
from .events import AbstractEventLoop
from .futures import Future
FIRST_EXCEPTION = 'FIRST_EXCEPTION'
FIRST_COMPLETED = 'FIRST_COMPLETED'
ALL_COMPLETED = 'ALL_COMPLETED'
_T = TypeVar('_T')
def coroutine(f: _T) -> _T: ... # Here comes and go a function
def sleep(delay: float, result: _T = ..., loop: AbstractEventLoop = ...) -> Future[_T]: ...
def wait(fs: List[Task[_T]], *, loop: AbstractEventLoop = ...,
timeout: float = ..., return_when: str = ...) -> Future[Tuple[Set[Future[_T]], Set[Future[_T]]]]: ...

View File

@@ -0,0 +1,39 @@
from typing import Dict, Any, TypeVar, Mapping, List
__all__ = ['BaseTransport', 'ReadTransport', 'WriteTransport',
'Transport', 'DatagramTransport', 'SubprocessTransport',
]
class BaseTransport:
def __init__(self, extra: Mapping[Any, Any] = ...) -> None: ...
def get_extra_info(self, name: Any, default: Any = ...) -> Any: ...
def is_closing(self) -> bool: ...
def close(self) -> None: ...
class ReadTransport(BaseTransport):
def pause_reading(self) -> None: ...
def resume_reading(self) -> None: ...
class WriteTransport(BaseTransport):
def set_write_buffer_limits(
self, high: int = ..., low: int = ...) -> None: ...
def get_write_buffer_size(self) -> int: ...
def write(self, data: Any) -> None: ...
def writelines(self, list_of_data: List[Any]): ...
def write_eof(self) -> None: ...
def can_write_eof(self) -> bool: ...
def abort(self) -> None: ...
class Transport(ReadTransport, WriteTransport): ...
class DatagramTransport(BaseTransport):
def sendto(self, data: Any, addr: str = ...) -> None: ...
def abort(self) -> None: ...
class SubprocessTransport(BaseTransport):
def get_pid(self) -> int: ...
def get_returncode(self) -> int: ...
def get_pipe_transport(self, fd: int) -> BaseTransport: ...
def send_signal(self, signal: int) -> int: ...
def terminate(self) -> None: ...
def kill(self) -> None: ...