From 4cc5f734120842660e6874085fb0965f894512f8 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 11 Jul 2016 15:43:30 -0700 Subject: [PATCH 1/7] Add stub for cgi.parse_header(). --- stdlib/3/cgi.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/3/cgi.pyi b/stdlib/3/cgi.pyi index f251f311dee9..1e8f31f6268b 100644 --- a/stdlib/3/cgi.pyi +++ b/stdlib/3/cgi.pyi @@ -1 +1,4 @@ +from typing import Tuple + def escape(s: str, quote: bool = ...) -> str: ... +def parse_header(s: str) -> Tuple[str, Dict[str, str]]: ... From 2ba63d98db0311613b1e04957697e0a6fb1f5a40 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 11 Jul 2016 18:31:40 -0700 Subject: [PATCH 2/7] Improve asyncio stubs (far from complete) --- stdlib/3.4/asyncio/__init__.pyi | 20 +++++++++++ stdlib/3.4/asyncio/coroutines.pyi | 6 ++-- stdlib/3.4/asyncio/events.pyi | 25 ++++++++----- stdlib/3.4/asyncio/locks.pyi | 60 +++++++++++++++++++++++++++++++ stdlib/3.4/asyncio/protocols.pyi | 2 +- stdlib/3.4/asyncio/streams.pyi | 22 ++++++------ stdlib/3.4/asyncio/tasks.pyi | 4 +-- 7 files changed, 113 insertions(+), 26 deletions(-) create mode 100644 stdlib/3.4/asyncio/locks.pyi diff --git a/stdlib/3.4/asyncio/__init__.pyi b/stdlib/3.4/asyncio/__init__.pyi index 171ab011592e..b791c0eb20d2 100644 --- a/stdlib/3.4/asyncio/__init__.pyi +++ b/stdlib/3.4/asyncio/__init__.pyi @@ -1,4 +1,7 @@ """The asyncio package, tracking PEP 3156.""" + +from typing import Type + from asyncio.coroutines import ( coroutine as coroutine, iscoroutinefunction as iscoroutinefunction, @@ -48,7 +51,13 @@ from asyncio.events import ( AbstractEventLoop as AbstractEventLoop, AbstractServer as AbstractServer, Handle as Handle, + 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, + set_event_loop as set_event_loop, + new_event_loop as new_event_loop, + get_child_watcher as get_child_watcher, + set_child_watcher as set_child_watcher, ) from asyncio.queues import ( Queue as Queue, @@ -58,5 +67,16 @@ from asyncio.queues import ( QueueFull as QueueFull, QueueEmpty as QueueEmpty, ) +from asyncio.locks import ( + Lock as Lock, + Event as Event, + Condition as Condition, + Semaphore as Semaphore, + BoundedSemaphore as BoundedSemaphore, +) + +SelectorEventLoop = ... # type: Type[AbstractEventLoop] +ProactorEventLoop = ... # type: Type[AbstractEventLoop] # TODO: Windows only +DefaultEventLoopPolicy = ... # type: Type[AbstractEventLoopPolicy] __all__ = ... # type: str diff --git a/stdlib/3.4/asyncio/coroutines.pyi b/stdlib/3.4/asyncio/coroutines.pyi index 455e36d257b3..668c83b716b5 100644 --- a/stdlib/3.4/asyncio/coroutines.pyi +++ b/stdlib/3.4/asyncio/coroutines.pyi @@ -1,9 +1,9 @@ -from typing import Callable, Any, TypeVar +from typing import Any, Callable, Generator, TypeVar __all__ = ... # type: str -_T = TypeVar('_T') +_F = TypeVar('_F', bound=Callable[..., Any]) -def coroutine(func: _T) -> _T: ... +def coroutine(func: _F) -> _F: ... def iscoroutinefunction(func: Callable[..., Any]) -> bool: ... def iscoroutine(obj: Any) -> bool: ... diff --git a/stdlib/3.4/asyncio/events.pyi b/stdlib/3.4/asyncio/events.pyi index 6b4f11afa3ae..de63474b4974 100644 --- a/stdlib/3.4/asyncio/events.pyi +++ b/stdlib/3.4/asyncio/events.pyi @@ -1,4 +1,4 @@ -from typing import Any, Awaitable, TypeVar, List, Callable, Tuple, Union, Dict, Generator +from typing import Any, TypeVar, List, Callable, Tuple, Union, Dict, Generator, Iterable from abc import ABCMeta, abstractmethod from asyncio.futures import Future from asyncio.coroutines import coroutine @@ -25,13 +25,13 @@ class Handle: class AbstractServer: def close(self) -> None: ... @coroutine - def wait_closed(self) -> None: ... + def wait_closed(self) -> Future[None]: ... class AbstractEventLoop(metaclass=ABCMeta): @abstractmethod def run_forever(self) -> None: ... @abstractmethod - def run_until_complete(self, future: Union[Awaitable[_T], Future[_T], Generator[Any, Any, _T]]) -> _T: ... + def run_until_complete(self, future: Union[Iterable[_T], Future[_T], Generator[Any, Any, _T]]) -> _T: ... @abstractmethod def stop(self) -> None: ... @abstractmethod @@ -58,9 +58,9 @@ class AbstractEventLoop(metaclass=ABCMeta): # Network I/O methods returning Futures. @abstractmethod def getaddrinfo(self, host: str, port: int, *, - family: int = ..., type: int = ..., proto: int = ..., flags: int = ...) -> List[Tuple[int, int, int, str, tuple]]: ... + family: int = ..., type: int = ..., proto: int = ..., flags: int = ...) -> Future[List[Tuple[int, int, int, str, tuple]]]: ... @abstractmethod - def getnameinfo(self, sockaddr: tuple, flags: int = ...) -> Tuple[str, int]: ... + def getnameinfo(self, sockaddr: tuple, flags: int = ...) -> Future[Tuple[str, int]]: ... @abstractmethod def create_connection(self, protocol_factory: Any, host: str = ..., port: int = ..., *, ssl: Any = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: Any = ..., @@ -152,18 +152,25 @@ class AbstractEventLoopPolicy(metaclass=ABCMeta): @abstractmethod def set_event_loop(self, loop: AbstractEventLoop): ... @abstractmethod - def new_event_loop(self) -> Any: ... # return selector_events.BaseSelectorEventLoop + def new_event_loop(self) -> AbstractEventLoop: ... # Child processes handling (Unix only). @abstractmethod - def get_child_watcher(self) -> Any: ... # return unix_events.AbstractChildWatcher + def get_child_watcher(self) -> Any: ... # TODO: unix_events.AbstractChildWatcher @abstractmethod - def set_child_watcher(self, watcher: Any) -> None: ... # gen unix_events.AbstractChildWatcher + def set_child_watcher(self, watcher: Any) -> None: ... # TODO: unix_events.AbstractChildWatcher class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy): def __init__(self) -> None: ... def get_event_loop(self) -> AbstractEventLoop: ... def set_event_loop(self, loop: AbstractEventLoop): ... - def new_event_loop(self) -> Any: ... # Same return than AbstractEventLoop + def new_event_loop(self) -> AbstractEventLoop: ... +def get_event_loop_policy() -> AbstractEventLoopPolicy: ... +def set_event_loop_policy(policy: AbstractEventLoopPolicy) -> None: ... def get_event_loop() -> AbstractEventLoop: ... +def set_event_loop(loop: AbstractEventLoop) -> None: ... +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 diff --git a/stdlib/3.4/asyncio/locks.pyi b/stdlib/3.4/asyncio/locks.pyi new file mode 100644 index 000000000000..f9d19c23843d --- /dev/null +++ b/stdlib/3.4/asyncio/locks.pyi @@ -0,0 +1,60 @@ +from typing import Any, Callable, Generator, Iterable, Iterator, TypeVar, Union + +from .coroutines import coroutine +from .events import AbstractEventLoop +from .futures import Future + +T = TypeVar('T') + +__all__ = ... # type: str + +class _ContextManager: + def __init__(self, lock: Union[Lock, Semaphore]) -> None: ... + def __enter__(self) -> object: ... + def __exit__(self, *args: Any) -> None: ... + +class _ContextManagerMixin(Future[_ContextManager]): + # Apparently this exists to *prohibit* use as a context manager. + def __enter__(self) -> object: ... + def __exit__(self, *args: Any) -> None: ... + def __iter__(self) -> Generator[Any, None, _ContextManager]: ... + def __aenter__(self): ... + def __aexit__(self, exc_type, exc, tb): ... + +class Lock(_ContextManagerMixin): + def __init__(self, *, loop: AbstractEventLoop = None) -> None: ... + def locked(self) -> bool: ... + @coroutine + def acquire(self) -> Future[bool]: ... + def release(self) -> None: ... + +class Event: + def __init__(self, *, loop: AbstractEventLoop = None) -> None: ... + def is_set(self) -> bool: ... + def set(self) -> None: ... + def clear(self) -> None: ... + + def wait(self) -> bool: ... + +class Condition(_ContextManagerMixin): + def __init__(self, lock: Lock = None, *, loop: AbstractEventLoop = None) -> None: ... + def locked(self) -> bool: ... + @coroutine + def acquire(self) -> Future[bool]: ... + def release(self) -> None: ... + @coroutine + def wait(self) -> Future[bool]: ... + @coroutine + def wait_for(self, predicate: Callable[[], T]) -> Future[T]: ... + def notify(self, n: int = 1) -> None: ... + def notify_all(self) -> None: ... + +class Semaphore(_ContextManagerMixin): + def __init__(self, value: int = 1, *, loop: AbstractEventLoop = None) -> None: ... + def locked(self) -> bool: ... + @coroutine + def acquire(self) -> Future[bool]: ... + def release(self) -> None: ... + +class BoundedSemaphore(Semaphore): + def __init__(self, value=1, *, loop: AbstractEventLoop = None) -> None: ... diff --git a/stdlib/3.4/asyncio/protocols.pyi b/stdlib/3.4/asyncio/protocols.pyi index 8cae805121d6..9ad7e4ea1814 100644 --- a/stdlib/3.4/asyncio/protocols.pyi +++ b/stdlib/3.4/asyncio/protocols.pyi @@ -11,7 +11,7 @@ class BaseProtocol: def resume_writing(self) -> None: ... class Protocol(BaseProtocol): - def data_received(self, data: AnyStr) -> None: ... + def data_received(self, data: bytes) -> None: ... def eof_received(self) -> bool: ... class DatagramProtocol(BaseProtocol): diff --git a/stdlib/3.4/asyncio/streams.pyi b/stdlib/3.4/asyncio/streams.pyi index a30a9501d67a..c9086b53ac76 100644 --- a/stdlib/3.4/asyncio/streams.pyi +++ b/stdlib/3.4/asyncio/streams.pyi @@ -1,4 +1,4 @@ -from typing import Iterable, Tuple, Callable, Any, AnyStr +from typing import Any, Callable, Generator, Iterable, Tuple ClientConnectedCallback = Callable[[Tuple[StreamReader, StreamWriter]], None] import socket @@ -23,7 +23,7 @@ def open_connection( *, loop: events.AbstractEventLoop = ..., limit: int = ..., - **kwds: Any) -> Tuple[StreamReader, StreamWriter]: ... + **kwds: Any) -> Generator[Any, None, Tuple[StreamReader, StreamWriter]]: ... @coroutines.coroutine def start_server( @@ -62,7 +62,7 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol): 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 data_received(self, data: bytes) -> None: ... def eof_received(self) -> bool: ... class StreamWriter: @@ -73,12 +73,12 @@ class StreamWriter: 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(self, data: bytes) -> None: ... + def writelines(self, data: Iterable[bytes]) -> 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 get_extra_info(self, name: str, default: Any = ...) -> Any: ... def drain(self) -> None: ... class StreamReader: @@ -90,12 +90,12 @@ class StreamReader: def set_transport(self, transport: transports.BaseTransport) -> None: ... def feed_eof(self) -> None: ... def at_eof(self) -> bool: ... - def feed_data(self, data: AnyStr): ... + def feed_data(self, data: bytes): ... @coroutines.coroutine - def readline(self) -> str: ... + def readline(self) -> Generator[Any, None, bytes]: ... @coroutines.coroutine - def readuntil(self, separator=b'\n') -> str: ... + def readuntil(self, separator=b'\n') -> Generator[Any, None, bytes]: ... @coroutines.coroutine - def read(self, n=-1) -> str: ... + def read(self, n=-1) -> Generator[Any, None, bytes]: ... @coroutines.coroutine - def readexactly(self, n) -> str: ... + def readexactly(self, n) -> Generator[Any, None, bytes]: ... diff --git a/stdlib/3.4/asyncio/tasks.pyi b/stdlib/3.4/asyncio/tasks.pyi index 66abd00fb3e7..91dc7a386eef 100644 --- a/stdlib/3.4/asyncio/tasks.pyi +++ b/stdlib/3.4/asyncio/tasks.pyi @@ -1,4 +1,4 @@ -from typing import Any, Iterable, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable, Generator +from typing import Any, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable, Generator, Iterable __all__ = ... # type: str @@ -22,7 +22,7 @@ class Task(Future[_T], Generic[_T]): def current_task(cls, loop: AbstractEventLoop = ...) -> Task: ... @classmethod def all_tasks(cls, loop: AbstractEventLoop = ...) -> Set[Task]: ... - def __init__(self, coro: Union[Future[_T], Generator[Any, None, _T]], *, loop: AbstractEventLoop = ...) -> None: ... + def __init__(self, coro: Union[Iterable[_T], Future[_T], Generator[Any, None, _T]], *, loop: AbstractEventLoop = ...) -> None: ... def __repr__(self) -> str: ... def get_stack(self, *, limit: int = ...) -> List[Any]: ... # return List[stackframe] def print_stack(self, *, limit: int = ..., file: TextIO = ...) -> None: ... From c811e8a8bb015c1fb62877528c26e40cefcf4a61 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 14 Jul 2016 11:58:27 -0700 Subject: [PATCH 3/7] More asyncio changes. --- stdlib/3.4/asyncio/events.pyi | 4 ++-- stdlib/3.4/asyncio/futures.pyi | 5 +++-- stdlib/3.4/asyncio/locks.pyi | 1 - stdlib/3.4/asyncio/tasks.pyi | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stdlib/3.4/asyncio/events.pyi b/stdlib/3.4/asyncio/events.pyi index de63474b4974..7c16ef78c09f 100644 --- a/stdlib/3.4/asyncio/events.pyi +++ b/stdlib/3.4/asyncio/events.pyi @@ -1,4 +1,4 @@ -from typing import Any, TypeVar, List, Callable, Tuple, Union, Dict, Generator, Iterable +from typing import Any, TypeVar, List, Callable, Tuple, Union, Dict, Generator, Iterable, Awaitable from abc import ABCMeta, abstractmethod from asyncio.futures import Future from asyncio.coroutines import coroutine @@ -31,7 +31,7 @@ class AbstractEventLoop(metaclass=ABCMeta): @abstractmethod def run_forever(self) -> None: ... @abstractmethod - def run_until_complete(self, future: Union[Iterable[_T], Future[_T], Generator[Any, Any, _T]]) -> _T: ... + def run_until_complete(self, future: Union[Awaitable[_T], Iterable[_T], Future[_T], Generator[Any, Any, _T]]) -> _T: ... @abstractmethod def stop(self) -> None: ... @abstractmethod diff --git a/stdlib/3.4/asyncio/futures.pyi b/stdlib/3.4/asyncio/futures.pyi index a3de8a8fd468..eab1d4cfba64 100644 --- a/stdlib/3.4/asyncio/futures.pyi +++ b/stdlib/3.4/asyncio/futures.pyi @@ -1,4 +1,4 @@ -from typing import Any, Union, Callable, TypeVar, List, Generic, Iterable, Generator +from typing import Any, Union, Callable, TypeVar, List, Generic, Iterable, Generator, Awaitable from .events import AbstractEventLoop __all__ = ... # type: str @@ -14,7 +14,7 @@ class _TracebackLogger: def clear(self) -> None: ... def __del__(self) -> None: ... -class Future(Iterable[_T], Generic[_T]): +class Future(Iterable[_T], Awaitable[_T], Generic[_T]): _state = ... # type: str _exception = ... # type: BaseException _blocking = False @@ -35,3 +35,4 @@ class Future(Iterable[_T], Generic[_T]): def set_exception(self, exception: Union[type, BaseException]) -> None: ... def _copy_state(self, other: Any) -> None: ... def __iter__(self) -> Generator[Any, None, _T]: ... + def __await__(self) -> Generator[Any, None, _T]: ... diff --git a/stdlib/3.4/asyncio/locks.pyi b/stdlib/3.4/asyncio/locks.pyi index f9d19c23843d..4d665ae434da 100644 --- a/stdlib/3.4/asyncio/locks.pyi +++ b/stdlib/3.4/asyncio/locks.pyi @@ -17,7 +17,6 @@ class _ContextManagerMixin(Future[_ContextManager]): # Apparently this exists to *prohibit* use as a context manager. def __enter__(self) -> object: ... def __exit__(self, *args: Any) -> None: ... - def __iter__(self) -> Generator[Any, None, _ContextManager]: ... def __aenter__(self): ... def __aexit__(self, exc_type, exc, tb): ... diff --git a/stdlib/3.4/asyncio/tasks.pyi b/stdlib/3.4/asyncio/tasks.pyi index 91dc7a386eef..57f1eac9fc52 100644 --- a/stdlib/3.4/asyncio/tasks.pyi +++ b/stdlib/3.4/asyncio/tasks.pyi @@ -1,4 +1,4 @@ -from typing import Any, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable, Generator, Iterable +from typing import Any, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable, Generator, Iterable, Awaitable __all__ = ... # type: str @@ -22,7 +22,7 @@ class Task(Future[_T], Generic[_T]): def current_task(cls, loop: AbstractEventLoop = ...) -> Task: ... @classmethod def all_tasks(cls, loop: AbstractEventLoop = ...) -> Set[Task]: ... - def __init__(self, coro: Union[Iterable[_T], Future[_T], Generator[Any, None, _T]], *, loop: AbstractEventLoop = ...) -> None: ... + def __init__(self, coro: Union[Awaitable[_T], Iterable[_T], Future[_T], Generator[Any, None, _T]], *, loop: AbstractEventLoop = ...) -> None: ... def __repr__(self) -> str: ... def get_stack(self, *, limit: int = ...) -> List[Any]: ... # return List[stackframe] def print_stack(self, *, limit: int = ..., file: TextIO = ...) -> None: ... From 9bdcae2dc57564f3184ac2cf24a35e3830abc89d Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 14 Jul 2016 13:35:12 -0700 Subject: [PATCH 4/7] Use @overload to solve strange test failures. --- stdlib/3.4/asyncio/events.pyi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/3.4/asyncio/events.pyi b/stdlib/3.4/asyncio/events.pyi index 7c16ef78c09f..eb9861350f82 100644 --- a/stdlib/3.4/asyncio/events.pyi +++ b/stdlib/3.4/asyncio/events.pyi @@ -1,4 +1,4 @@ -from typing import Any, TypeVar, List, Callable, Tuple, Union, Dict, Generator, Iterable, Awaitable +from typing import Any, TypeVar, List, Callable, Tuple, Union, Dict, Generator, Iterable, Awaitable, overload from abc import ABCMeta, abstractmethod from asyncio.futures import Future from asyncio.coroutines import coroutine @@ -30,8 +30,12 @@ class AbstractServer: class AbstractEventLoop(metaclass=ABCMeta): @abstractmethod def run_forever(self) -> None: ... + @overload @abstractmethod - def run_until_complete(self, future: Union[Awaitable[_T], Iterable[_T], Future[_T], Generator[Any, Any, _T]]) -> _T: ... + def run_until_complete(self, future: Union[Iterable[_T], Future[_T], Generator[Any, Any, _T]]) -> _T: ... + @overload + @abstractmethod + def run_until_complete(self, future: Awaitable[_T]) -> _T: ... @abstractmethod def stop(self) -> None: ... @abstractmethod From 9eb03475691ab55f2acd7da5a97abaf78ee51281 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 15 Jul 2016 13:27:04 -0700 Subject: [PATCH 5/7] Add some TODOs. Make ProactorEventLoop conditional. --- stdlib/3.4/asyncio/__init__.pyi | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/stdlib/3.4/asyncio/__init__.pyi b/stdlib/3.4/asyncio/__init__.pyi index b791c0eb20d2..b4c47435cd34 100644 --- a/stdlib/3.4/asyncio/__init__.pyi +++ b/stdlib/3.4/asyncio/__init__.pyi @@ -1,5 +1,6 @@ """The asyncio package, tracking PEP 3156.""" +import sys from typing import Type from asyncio.coroutines import ( @@ -75,8 +76,14 @@ from asyncio.locks import ( BoundedSemaphore as BoundedSemaphore, ) +# TODO: It should be possible to instantiate these classes, but mypy +# currently disallows this. +# See https://github.com/python/mypy/issues/1843 SelectorEventLoop = ... # type: Type[AbstractEventLoop] -ProactorEventLoop = ... # type: Type[AbstractEventLoop] # TODO: Windows only +if sys.platform == 'win32': + ProactorEventLoop = ... # type: Type[AbstractEventLoop] # TODO: Windows only DefaultEventLoopPolicy = ... # type: Type[AbstractEventLoopPolicy] +# TODO: AbstractChildWatcher (UNIX only) + __all__ = ... # type: str From fe2491b485aa0bd6ec4a0fe7e12f32dd98b756e0 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 15 Jul 2016 13:30:12 -0700 Subject: [PATCH 6/7] Future should not inherit from Awaitable or implement __await__. At least not yet. --- stdlib/3.4/asyncio/futures.pyi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stdlib/3.4/asyncio/futures.pyi b/stdlib/3.4/asyncio/futures.pyi index eab1d4cfba64..a3de8a8fd468 100644 --- a/stdlib/3.4/asyncio/futures.pyi +++ b/stdlib/3.4/asyncio/futures.pyi @@ -1,4 +1,4 @@ -from typing import Any, Union, Callable, TypeVar, List, Generic, Iterable, Generator, Awaitable +from typing import Any, Union, Callable, TypeVar, List, Generic, Iterable, Generator from .events import AbstractEventLoop __all__ = ... # type: str @@ -14,7 +14,7 @@ class _TracebackLogger: def clear(self) -> None: ... def __del__(self) -> None: ... -class Future(Iterable[_T], Awaitable[_T], Generic[_T]): +class Future(Iterable[_T], Generic[_T]): _state = ... # type: str _exception = ... # type: BaseException _blocking = False @@ -35,4 +35,3 @@ class Future(Iterable[_T], Awaitable[_T], Generic[_T]): def set_exception(self, exception: Union[type, BaseException]) -> None: ... def _copy_state(self, other: Any) -> None: ... def __iter__(self) -> Generator[Any, None, _T]: ... - def __await__(self) -> Generator[Any, None, _T]: ... From 367b6ec564d0fc4011b32163898acf13b0664a34 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 15 Jul 2016 13:35:21 -0700 Subject: [PATCH 7/7] Fix AbstractServer.wait_closed() return type. It's a generator, not a future. --- stdlib/3.4/asyncio/events.pyi | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/stdlib/3.4/asyncio/events.pyi b/stdlib/3.4/asyncio/events.pyi index eb9861350f82..43b527b384ae 100644 --- a/stdlib/3.4/asyncio/events.pyi +++ b/stdlib/3.4/asyncio/events.pyi @@ -1,4 +1,4 @@ -from typing import Any, TypeVar, List, Callable, Tuple, Union, Dict, Generator, Iterable, Awaitable, overload +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 @@ -25,17 +25,13 @@ class Handle: class AbstractServer: def close(self) -> None: ... @coroutine - def wait_closed(self) -> Future[None]: ... + def wait_closed(self) -> Generator[Any, Any, None]: ... class AbstractEventLoop(metaclass=ABCMeta): @abstractmethod def run_forever(self) -> None: ... - @overload @abstractmethod - def run_until_complete(self, future: Union[Iterable[_T], Future[_T], Generator[Any, Any, _T]]) -> _T: ... - @overload - @abstractmethod - def run_until_complete(self, future: Awaitable[_T]) -> _T: ... + def run_until_complete(self, future: Union[Awaitable[_T], Future[_T], Generator[Any, Any, _T]]) -> _T: ... @abstractmethod def stop(self) -> None: ... @abstractmethod