From 4d0a9e6d491efae6442d963a771854e980f8f78e Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Fri, 29 Jan 2016 15:53:21 -0800 Subject: [PATCH 1/7] Add type information for asyncio.coroutines --- stdlib/3.4/asyncio/__init__.pyi | 9 +++++++-- stdlib/3.4/asyncio/coroutines.pyi | 8 ++++++++ stdlib/3.4/asyncio/queues.pyi | 2 +- stdlib/3.4/asyncio/tasks.pyi | 3 +-- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 stdlib/3.4/asyncio/coroutines.pyi diff --git a/stdlib/3.4/asyncio/__init__.pyi b/stdlib/3.4/asyncio/__init__.pyi index e22015e51..1b55d7064 100644 --- a/stdlib/3.4/asyncio/__init__.pyi +++ b/stdlib/3.4/asyncio/__init__.pyi @@ -1,9 +1,13 @@ """The asyncio package, tracking PEP 3156.""" +from asyncio.coroutines import ( + coroutine as coroutine, + iscoroutinefunction as iscoroutinefunction, + iscoroutine as iscoroutine, +) 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, @@ -27,7 +31,8 @@ from asyncio.queues import ( QueueEmpty as QueueEmpty, ) -__all__ = (futures.__all__ + +__all__ = (coroutines.__all__ + + futures.__all__ + tasks.__all__ + events.__all__ + queues.__all__) diff --git a/stdlib/3.4/asyncio/coroutines.pyi b/stdlib/3.4/asyncio/coroutines.pyi new file mode 100644 index 000000000..ad0178a10 --- /dev/null +++ b/stdlib/3.4/asyncio/coroutines.pyi @@ -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: ... diff --git a/stdlib/3.4/asyncio/queues.pyi b/stdlib/3.4/asyncio/queues.pyi index 720864aef..f945ab022 100644 --- a/stdlib/3.4/asyncio/queues.pyi +++ b/stdlib/3.4/asyncio/queues.pyi @@ -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 diff --git a/stdlib/3.4/asyncio/tasks.pyi b/stdlib/3.4/asyncio/tasks.pyi index 3adebe1ba..4475c4ab0 100644 --- a/stdlib/3.4/asyncio/tasks.pyi +++ b/stdlib/3.4/asyncio/tasks.pyi @@ -6,7 +6,7 @@ from asyncio.futures import Future # 'gather', 'shield', # ] -__all__ = ['coroutine', 'Task', 'sleep', +__all__ = ['Task', 'sleep', 'FIRST_COMPLETED', 'FIRST_EXCEPTION', 'ALL_COMPLETED', 'wait', 'wait_for'] @@ -14,7 +14,6 @@ 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]]]]: ... From 0f5c38a2ce9e99b8bfdbffc5f22cbaa371a69873 Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Fri, 29 Jan 2016 15:48:10 -0800 Subject: [PATCH 2/7] Add type information for asyncio.events.AbstractServer Add the appropriate types for AbstractServer in asyncio.events. wait_closed() is a couroutine, however in the implementation of AbstractServer not marked as such. We are adding the couroutine defintion here anyway, as we do want to make it typeable as a coroutine if necessary. --- stdlib/3.4/asyncio/__init__.pyi | 1 + stdlib/3.4/asyncio/events.pyi | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/stdlib/3.4/asyncio/__init__.pyi b/stdlib/3.4/asyncio/__init__.pyi index 1b55d7064..6c5dbe222 100644 --- a/stdlib/3.4/asyncio/__init__.pyi +++ b/stdlib/3.4/asyncio/__init__.pyi @@ -19,6 +19,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, ) diff --git a/stdlib/3.4/asyncio/events.pyi b/stdlib/3.4/asyncio/events.pyi index afdd6397e..c80506cce 100644 --- a/stdlib/3.4/asyncio/events.pyi +++ b/stdlib/3.4/asyncio/events.pyi @@ -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 From 23ecee29d3555708325802c80b6b302b18a1fccf Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Fri, 29 Jan 2016 16:08:57 -0800 Subject: [PATCH 3/7] Add type information for asyncio.transports --- stdlib/3.4/asyncio/__init__.pyi | 9 +++++++ stdlib/3.4/asyncio/transports.pyi | 39 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 stdlib/3.4/asyncio/transports.pyi diff --git a/stdlib/3.4/asyncio/__init__.pyi b/stdlib/3.4/asyncio/__init__.pyi index 6c5dbe222..3b9a237ef 100644 --- a/stdlib/3.4/asyncio/__init__.pyi +++ b/stdlib/3.4/asyncio/__init__.pyi @@ -4,6 +4,14 @@ from asyncio.coroutines import ( iscoroutinefunction as iscoroutinefunction, iscoroutine as iscoroutine, ) +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, ) @@ -33,6 +41,7 @@ from asyncio.queues import ( ) __all__ = (coroutines.__all__ + + transports.__all__ + futures.__all__ + tasks.__all__ + events.__all__ + diff --git a/stdlib/3.4/asyncio/transports.pyi b/stdlib/3.4/asyncio/transports.pyi new file mode 100644 index 000000000..e12693079 --- /dev/null +++ b/stdlib/3.4/asyncio/transports.pyi @@ -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: ... From 3910b7936116d9fa6f2d25fccfbafb7e8c5c3747 Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Fri, 29 Jan 2016 16:10:48 -0800 Subject: [PATCH 4/7] Add type information for asyncio.protocols --- stdlib/3.4/asyncio/__init__.pyi | 7 +++++++ stdlib/3.4/asyncio/protocols.pyi | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 stdlib/3.4/asyncio/protocols.pyi diff --git a/stdlib/3.4/asyncio/__init__.pyi b/stdlib/3.4/asyncio/__init__.pyi index 3b9a237ef..640323e4c 100644 --- a/stdlib/3.4/asyncio/__init__.pyi +++ b/stdlib/3.4/asyncio/__init__.pyi @@ -4,6 +4,12 @@ from asyncio.coroutines import ( iscoroutinefunction as iscoroutinefunction, iscoroutine as iscoroutine, ) +from asyncio.protocols import ( + BaseProtocol as BaseProtocol, + Protocol as Protocol, + DatagramProtocol as DatagramProtocol, + SubprocessProtocol as SubprocessProtocol, +) from asyncio.transports import ( BaseTransport as BaseTransport, ReadTransport as ReadTransport, @@ -41,6 +47,7 @@ from asyncio.queues import ( ) __all__ = (coroutines.__all__ + + protocols.__all__ + transports.__all__ + futures.__all__ + tasks.__all__ + diff --git a/stdlib/3.4/asyncio/protocols.pyi b/stdlib/3.4/asyncio/protocols.pyi new file mode 100644 index 000000000..3c47eff81 --- /dev/null +++ b/stdlib/3.4/asyncio/protocols.pyi @@ -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: ... From bce32b0382841d3476cac2a607aaa5440ce91e4d Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Fri, 29 Jan 2016 16:13:35 -0800 Subject: [PATCH 5/7] Add type information for asyncio.streams --- stdlib/3.4/asyncio/__init__.pyi | 10 +++ stdlib/3.4/asyncio/streams.pyi | 104 ++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 stdlib/3.4/asyncio/streams.pyi diff --git a/stdlib/3.4/asyncio/__init__.pyi b/stdlib/3.4/asyncio/__init__.pyi index 640323e4c..a5e882595 100644 --- a/stdlib/3.4/asyncio/__init__.pyi +++ b/stdlib/3.4/asyncio/__init__.pyi @@ -10,6 +10,15 @@ from asyncio.protocols import ( 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.transports import ( BaseTransport as BaseTransport, ReadTransport as ReadTransport, @@ -48,6 +57,7 @@ from asyncio.queues import ( __all__ = (coroutines.__all__ + protocols.__all__ + + streams.__all__ + transports.__all__ + futures.__all__ + tasks.__all__ + diff --git a/stdlib/3.4/asyncio/streams.pyi b/stdlib/3.4/asyncio/streams.pyi new file mode 100644 index 000000000..39f3b0c5e --- /dev/null +++ b/stdlib/3.4/asyncio/streams.pyi @@ -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: ... From 3223a693d51b34ea9855d6a0a03887309b9e68c0 Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Thu, 28 Jan 2016 19:41:01 -0800 Subject: [PATCH 6/7] Add type information for asyncio.subprocess --- stdlib/3.4/asyncio/__init__.pyi | 5 +++ stdlib/3.4/asyncio/subprocess.pyi | 60 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 stdlib/3.4/asyncio/subprocess.pyi diff --git a/stdlib/3.4/asyncio/__init__.pyi b/stdlib/3.4/asyncio/__init__.pyi index a5e882595..0a85a3b6f 100644 --- a/stdlib/3.4/asyncio/__init__.pyi +++ b/stdlib/3.4/asyncio/__init__.pyi @@ -19,6 +19,10 @@ from asyncio.streams import ( 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, @@ -58,6 +62,7 @@ from asyncio.queues import ( __all__ = (coroutines.__all__ + protocols.__all__ + streams.__all__ + + subprocess.__all__ + transports.__all__ + futures.__all__ + tasks.__all__ + diff --git a/stdlib/3.4/asyncio/subprocess.pyi b/stdlib/3.4/asyncio/subprocess.pyi new file mode 100644 index 000000000..8d383076a --- /dev/null +++ b/stdlib/3.4/asyncio/subprocess.pyi @@ -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: ... From 70ddf02d217c9588857ff9dc5d0efce03f611de1 Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Fri, 19 Feb 2016 19:51:11 -0800 Subject: [PATCH 7/7] Use relative imports in asyncio.tasks and asyncio.futures --- stdlib/3.4/asyncio/futures.pyi | 2 +- stdlib/3.4/asyncio/tasks.pyi | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/stdlib/3.4/asyncio/futures.pyi b/stdlib/3.4/asyncio/futures.pyi index 37e72a157..81f2fb5e6 100644 --- a/stdlib/3.4/asyncio/futures.pyi +++ b/stdlib/3.4/asyncio/futures.pyi @@ -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', diff --git a/stdlib/3.4/asyncio/tasks.pyi b/stdlib/3.4/asyncio/tasks.pyi index 4475c4ab0..14ca97b5d 100644 --- a/stdlib/3.4/asyncio/tasks.pyi +++ b/stdlib/3.4/asyncio/tasks.pyi @@ -1,15 +1,12 @@ 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__ = ['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'