11import sys
22from asyncio .events import AbstractEventLoop
3- from collections .abc import Awaitable , Callable , Coroutine , Generator , Iterable
3+ from collections .abc import Awaitable , Callable , Coroutine , Generator
44from contextvars import Context
5- from types import FrameType
5+ from types import FrameType , GenericAlias
66from typing import Any , Literal , TextIO , TypeVar
77from typing_extensions import Self , TypeAlias
88
9- if sys .version_info >= (3 , 9 ):
10- from types import GenericAlias
11-
129_T = TypeVar ("_T" )
1310_T_co = TypeVar ("_T_co" , covariant = True )
1411_TaskYieldType : TypeAlias = Future [object ] | None
1512
16- class Future (Awaitable [_T ], Iterable [ _T ] ):
13+ class Future (Awaitable [_T ]):
1714 _state : str
1815 @property
1916 def _exception (self ) -> BaseException | None : ...
@@ -29,11 +26,7 @@ class Future(Awaitable[_T], Iterable[_T]):
2926 @property
3027 def _callbacks (self ) -> list [tuple [Callable [[Self ], Any ], Context ]]: ...
3128 def add_done_callback (self , fn : Callable [[Self ], object ], / , * , context : Context | None = None ) -> None : ...
32- if sys .version_info >= (3 , 9 ):
33- def cancel (self , msg : Any | None = None ) -> bool : ...
34- else :
35- def cancel (self ) -> bool : ...
36-
29+ def cancel (self , msg : Any | None = None ) -> bool : ...
3730 def cancelled (self ) -> bool : ...
3831 def done (self ) -> bool : ...
3932 def result (self ) -> _T : ...
@@ -45,15 +38,12 @@ class Future(Awaitable[_T], Iterable[_T]):
4538 def __await__ (self ) -> Generator [Any , None , _T ]: ...
4639 @property
4740 def _loop (self ) -> AbstractEventLoop : ...
48- if sys .version_info >= (3 , 9 ):
49- def __class_getitem__ (cls , item : Any , / ) -> GenericAlias : ...
41+ def __class_getitem__ (cls , item : Any , / ) -> GenericAlias : ...
5042
5143if sys .version_info >= (3 , 12 ):
5244 _TaskCompatibleCoro : TypeAlias = Coroutine [Any , Any , _T_co ]
53- elif sys .version_info >= (3 , 9 ):
54- _TaskCompatibleCoro : TypeAlias = Generator [_TaskYieldType , None , _T_co ] | Coroutine [Any , Any , _T_co ]
5545else :
56- _TaskCompatibleCoro : TypeAlias = Generator [_TaskYieldType , None , _T_co ] | Awaitable [ _T_co ]
46+ _TaskCompatibleCoro : TypeAlias = Generator [_TaskYieldType , None , _T_co ] | Coroutine [ Any , Any , _T_co ]
5747
5848# mypy and pyright complain that a subclass of an invariant class shouldn't be covariant.
5949# While this is true in general, here it's sort-of okay to have a covariant subclass,
@@ -99,13 +89,8 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
9989 if sys .version_info >= (3 , 11 ):
10090 def cancelling (self ) -> int : ...
10191 def uncancel (self ) -> int : ...
102- if sys .version_info < (3 , 9 ):
103- @classmethod
104- def current_task (cls , loop : AbstractEventLoop | None = None ) -> Task [Any ] | None : ...
105- @classmethod
106- def all_tasks (cls , loop : AbstractEventLoop | None = None ) -> set [Task [Any ]]: ...
107- if sys .version_info >= (3 , 9 ):
108- def __class_getitem__ (cls , item : Any , / ) -> GenericAlias : ...
92+
93+ def __class_getitem__ (cls , item : Any , / ) -> GenericAlias : ...
10994
11095def get_event_loop () -> AbstractEventLoop : ...
11196def get_running_loop () -> AbstractEventLoop : ...
0 commit comments