Changes required by mypy async-await support (#435)

This commit is contained in:
Guido van Rossum
2016-08-03 17:01:35 -07:00
committed by GitHub
parent 5a5138aa1e
commit de4e87f574
5 changed files with 30 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, Awaitable, TypeVar, List, Callable, Tuple, Union, Dict, Generator
from typing import Any, Awaitable, TypeVar, List, Callable, Tuple, Union, Dict, Generator, overload
from abc import ABCMeta, abstractmethod
from asyncio.futures import Future
from asyncio.coroutines import coroutine
@@ -30,8 +30,15 @@ class AbstractServer:
class AbstractEventLoop(metaclass=ABCMeta):
@abstractmethod
def run_forever(self) -> None: ...
# Can't use a union, see mypy issue #1873.
@overload
@abstractmethod
def run_until_complete(self, future: Union[Awaitable[_T], Future[_T], Generator[Any, Any, _T]]) -> _T: ...
def run_until_complete(self, future: Generator[Any, Any, _T]) -> _T: ...
@overload
@abstractmethod
def run_until_complete(self, future: Awaitable[_T]) -> _T: ...
@abstractmethod
def stop(self) -> None: ...
@abstractmethod

View File

@@ -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]: ...

View File

@@ -33,7 +33,7 @@ def start_server(
*,
loop: events.AbstractEventLoop = ...,
limit: int = ...,
**kwds: Any) -> events.AbstractServer: ...
**kwds: Any) -> Generator[Any, None, events.AbstractServer]: ...
if hasattr(socket, 'AF_UNIX'):
@coroutines.coroutine
@@ -42,7 +42,7 @@ if hasattr(socket, 'AF_UNIX'):
*,
loop: events.AbstractEventLoop = ...,
limit: int = ...,
**kwds: Any): ...
**kwds: Any)-> Generator[Any, None, Tuple[StreamReader, StreamWriter]]: ...
@coroutines.coroutine
def start_unix_server(
@@ -51,7 +51,7 @@ if hasattr(socket, 'AF_UNIX'):
*,
loop: int = ...,
limit: int = ...,
**kwds: Any) -> events.AbstractServer: ...
**kwds: Any) -> Generator[Any, None, events.AbstractServer]: ...
class FlowControlMixin(protocols.Protocol): ...

View File

@@ -1,4 +1,4 @@
from typing import Any, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable, Generator, Iterable, Awaitable
from typing import Any, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable, Generator, Iterable, Awaitable, overload
__all__ = ... # type: str
@@ -22,7 +22,13 @@ 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[Awaitable[_T], Iterable[_T], Future[_T], Generator[Any, None, _T]], *, loop: AbstractEventLoop = ...) -> None: ...
# Can't use a union, see mypy issue #1873.
@overload
def __init__(self, coro: Generator[Any, None, _T], *, loop: AbstractEventLoop = ...) -> None: ...
@overload
def __init__(self, coro: Awaitable[_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: ...

View File

@@ -113,11 +113,15 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]):
@abstractmethod
def __iter__(self) -> 'Generator[_T_co, _T_contra, _V_co]': ...
class AbstractFuture(Generic[_T]): ...
class Awaitable(Generic[_T_co]):
@abstractmethod
def __await__(self) -> Generator[AbstractFuture[_T_co], Any, _T_co]:...
def __await__(self) -> Generator[Any, None, _T_co]:...
# NOTE: This type does not exist in typing.py or PEP 484.
# The parameters corrrespond to Generator, but the 4th is the original type.
class AwaitableGenerator(Generator[_T_co, _T_contra, _V_co], Awaitable[_T_co],
Generic[_T_co, _T_contra, _V_co, _S]):
pass
class AsyncIterable(Generic[_T_co]):
@abstractmethod