@@ -36,6 +36,7 @@ __all__ = (
36
36
)
37
37
38
38
_T = TypeVar ("_T" )
39
+ _T_co = TypeVar ("_T_co" , covariant = True )
39
40
_T1 = TypeVar ("_T1" )
40
41
_T2 = TypeVar ("_T2" )
41
42
_T3 = TypeVar ("_T3" )
@@ -265,21 +266,25 @@ else:
265
266
) -> tuple [set [Task [_T ]], set [Task [_T ]]]: ...
266
267
async def wait_for (fut : _FutureLike [_T ], timeout : float | None , * , loop : AbstractEventLoop | None = ...) -> _T : ...
267
268
268
- class Task (Future [_T ], Generic [_T ]):
269
+ # pyright complains that a subclass of an invariant class shouldn't be covariant.
270
+ # While this is true in general, here it's sort-of okay to have a covariant subclass,
271
+ # since the only reason why `asyncio.Future` is invariant is the `set_result()` method,
272
+ # and `asyncio.Task.set_result()` always raises.
273
+ class Task (Future [_T_co ], Generic [_T_co ]): # pyright: ignore[reportGeneralTypeIssues]
269
274
if sys .version_info >= (3 , 8 ):
270
275
def __init__ (
271
276
self ,
272
- coro : Generator [_TaskYieldType , None , _T ] | Awaitable [_T ],
277
+ coro : Generator [_TaskYieldType , None , _T_co ] | Awaitable [_T_co ],
273
278
* ,
274
279
loop : AbstractEventLoop = ...,
275
280
name : str | None = ...,
276
281
) -> None : ...
277
282
else :
278
283
def __init__ (
279
- self , coro : Generator [_TaskYieldType , None , _T ] | Awaitable [_T ], * , loop : AbstractEventLoop = ...
284
+ self , coro : Generator [_TaskYieldType , None , _T_co ] | Awaitable [_T_co ], * , loop : AbstractEventLoop = ...
280
285
) -> None : ...
281
286
if sys .version_info >= (3 , 8 ):
282
- def get_coro (self ) -> Generator [_TaskYieldType , None , _T ] | Awaitable [_T ]: ...
287
+ def get_coro (self ) -> Generator [_TaskYieldType , None , _T_co ] | Awaitable [_T_co ]: ...
283
288
def get_name (self ) -> str : ...
284
289
def set_name (self , __value : object ) -> None : ...
285
290
0 commit comments