Skip to content

Commit 82c930e

Browse files
JelleZijlstragvanrossum
authored andcommitted
Improve asyncio.tasks stubs (#2139)
- Use PEP 526-style variable annotations where possible - Use FrameType instead of Any - Remove workaround for mypy issue that was since fixed
1 parent f5a74fd commit 82c930e

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

stdlib/3.4/asyncio/tasks.pyi

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import (Any, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable,
22
Coroutine, Generator, Iterable, Awaitable, overload, Sequence, Iterator,
33
Optional)
4+
from types import FrameType
45
import concurrent.futures
56
from .events import AbstractEventLoop
67
from .futures import Future
@@ -15,9 +16,9 @@ _T4 = TypeVar('_T4')
1516
_T5 = TypeVar('_T5')
1617
_FutureT = Union[Future[_T], Generator[Any, None, _T], Awaitable[_T]]
1718

18-
FIRST_EXCEPTION = 'FIRST_EXCEPTION'
19-
FIRST_COMPLETED = 'FIRST_COMPLETED'
20-
ALL_COMPLETED = 'ALL_COMPLETED'
19+
FIRST_EXCEPTION: str
20+
FIRST_COMPLETED: str
21+
ALL_COMPLETED: str
2122

2223
def as_completed(fs: Sequence[_FutureT[_T]], *, loop: AbstractEventLoop = ...,
2324
timeout: Optional[float] = ...) -> Iterator[Generator[Any, None, _T]]: ...
@@ -57,22 +58,13 @@ def wait_for(fut: _FutureT[_T], timeout: Optional[float],
5758
*, loop: AbstractEventLoop = ...) -> Future[_T]: ...
5859

5960
class Task(Future[_T], Generic[_T]):
60-
_all_tasks = ... # type: Set[Task]
61-
_current_tasks = ... # type: Dict[AbstractEventLoop, Task]
6261
@classmethod
6362
def current_task(cls, loop: AbstractEventLoop = ...) -> Task: ...
6463
@classmethod
6564
def all_tasks(cls, loop: AbstractEventLoop = ...) -> Set[Task]: ...
66-
67-
# Can't use a union, see mypy issue #1873.
68-
@overload
69-
def __init__(self, coro: Generator[Any, None, _T],
70-
*, loop: AbstractEventLoop = ...) -> None: ...
71-
@overload
72-
def __init__(self, coro: Awaitable[_T], *, loop: AbstractEventLoop = ...) -> None: ...
73-
65+
def __init__(self, coro: Union[Generator[Any, None, _T], Awaitable[_T]], *, loop: AbstractEventLoop = ...) -> None: ...
7466
def __repr__(self) -> str: ...
75-
def get_stack(self, *, limit: int = ...) -> List[Any]: ... # return List[stackframe]
67+
def get_stack(self, *, limit: int = ...) -> List[FrameType]: ...
7668
def print_stack(self, *, limit: int = ..., file: TextIO = ...) -> None: ...
7769
def cancel(self) -> bool: ...
7870
def _step(self, value: Any = ..., exc: Exception = ...) -> None: ...

0 commit comments

Comments
 (0)