1414 Awaitable ,
1515 Callable ,
1616 Coroutine ,
17- Union ,
1817 cast ,
1918)
2019
@@ -81,10 +80,10 @@ def aio_sleep(seconds: float = 0) -> Awaitable:
8180 """Return sleep coroutine."""
8281
8382 if trio_installed and current_async_library () == "trio" :
84- return trio_sleep (seconds ) # noqa: ASYNC105
83+ return trio_sleep (seconds ) # noqa: ASYNC105 # type: ignore[]
8584
8685 if curio_installed and current_async_library () == "curio" :
87- return curio_sleep (seconds )
86+ return curio_sleep (seconds ) # type: ignore[]
8887
8988 return sleep (seconds )
9089
@@ -93,12 +92,12 @@ def aio_sleep(seconds: float = 0) -> Awaitable:
9392async def aio_spawn (fn : Callable [..., Awaitable ], * args , ** kwargs ):
9493 """Spawn a given coroutine."""
9594 if trio_installed and current_async_library () == "trio" :
96- async with open_nursery () as tasks :
95+ async with open_nursery () as tasks : # type: ignore[]
9796 tasks .start_soon (fn , * args , ** kwargs )
9897 yield tasks
9998
10099 elif curio_installed and current_async_library () == "curio" :
101- task = await curio_spawn (fn , * args , ** kwargs )
100+ task = await curio_spawn (fn , * args , ** kwargs ) # type: ignore[]
102101 yield task
103102 await task .join () # type: ignore [union-attr]
104103
@@ -118,18 +117,18 @@ async def aio_timeout(timeout: float): # noqa: ASYNC109
118117
119118 if trio_installed and current_async_library () == "trio" :
120119 try :
121- with trio_fail_after (timeout ):
120+ with trio_fail_after (timeout ): # type: ignore[]
122121 yield
123122
124- except TooSlowError :
123+ except TooSlowError : # type: ignore[]
125124 raise TimeoutError (f"{ timeout } s." ) from None
126125
127126 elif curio_installed and current_async_library () == "curio" :
128127 try :
129- async with curio_fail_after (timeout ):
128+ async with curio_fail_after (timeout ): # type: ignore[]
130129 yield
131130
132- except TaskTimeout :
131+ except TaskTimeout : # type: ignore[]
133132 raise TimeoutError (f"{ timeout } s." ) from None
134133
135134 else :
@@ -148,7 +147,7 @@ async def aio_wait(*aws: Awaitable, strategy: str = ALL_COMPLETED) -> Any:
148147 if trio_installed and current_async_library () == "trio" :
149148 send_channel , receive_channel = open_memory_channel (0 ) # type: ignore[var-annotated]
150149
151- async with open_nursery () as n :
150+ async with open_nursery () as n : # type: ignore[]
152151 for aw in aws :
153152 n .start_soon (trio_jockey , aw , send_channel )
154153
@@ -179,7 +178,7 @@ async def aio_wait(*aws: Awaitable, strategy: str = ALL_COMPLETED) -> Any:
179178 return [t .result () for t in done ] # type: ignore[attr-defined]
180179
181180
182- async def aio_cancel (task : Union [ asyncio . Task , Any ] ):
181+ async def aio_cancel (task ):
183182 """Cancel asyncio task / trio nursery."""
184183 if isinstance (task , asyncio .Task ):
185184 return task .cancel ()
@@ -193,7 +192,7 @@ async def aio_cancel(task: Union[asyncio.Task, Any]):
193192
194193
195194async def aio_stream_file (
196- filepath : Union [ str , Path ] , chunk_size : int = 32 * 1024
195+ filepath : Path | str , chunk_size : int = 32 * 1024
197196) -> AsyncGenerator [bytes , None ]:
198197 if trio_installed and current_async_library () == "trio" :
199198 async with await trio_open_file (filepath , "rb" ) as fp :
@@ -238,7 +237,7 @@ def json_dumps(content) -> bytes:
238237 ).encode ("utf-8" )
239238
240239
241- def json_loads (obj : Union [ bytes , str ] ) -> TJSON :
240+ def json_loads (obj : bytes | str ) -> TJSON :
242241 """Emulate orjson."""
243242 if isinstance (obj , bytes ):
244243 obj = obj .decode ("utf-8" )
0 commit comments