File tree 1 file changed +28
-0
lines changed
test_cases/stdlib/asyncio
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+
5
+
6
+ class Waiter :
7
+ def __init__ (self ) -> None :
8
+ self .tasks : list [asyncio .Task [object ]] = []
9
+
10
+ def add (self , t : asyncio .Task [object ]) -> None :
11
+ self .tasks .append (t )
12
+
13
+ async def join (self ) -> None :
14
+ await asyncio .wait (self .tasks )
15
+
16
+
17
+ async def foo () -> int :
18
+ ...
19
+
20
+
21
+ async def main () -> None :
22
+ # asyncio.Task is covariant in its type argument, which is unusual since its parent class
23
+ # asyncio.Future is invariant in its type argument. This is only sound because asyncio.Task
24
+ # is not actually Liskov substitutable for asyncio.Future: it does not implement set_result.
25
+ w = Waiter ()
26
+ t : asyncio .Task [int ] = asyncio .create_task (foo ())
27
+ w .add (t )
28
+ await w .join ()
You can’t perform that action at this time.
0 commit comments