mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-16 00:37:10 +08:00
Changes required by mypy async-await support (#435)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]: ...
|
||||
|
||||
@@ -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): ...
|
||||
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user