File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import asyncio
4+ import sys
45from typing import (
56 Any ,
67 AsyncIterable ,
1819 Type ,
1920 TypeVar ,
2021 Union ,
22+ TYPE_CHECKING ,
2123)
2224
25+ if TYPE_CHECKING :
26+ from _typeshed import SupportsAnext
27+
2328A = TypeVar ("A" )
2429T = TypeVar ("T" )
2530R = TypeVar ("R" )
@@ -494,6 +499,15 @@ async def blocking_dequeue(self) -> Tuple[int, T]:
494499 return ret
495500
496501
502+ # version of anext that always returns a Coroutine
503+ if sys .version_info >= (3 , 10 ):
504+ async def anext_cr (v : SupportsAnext [T ]) -> T :
505+ return await anext (v )
506+ else :
507+ async def anext_cr (v : SupportsAnext [T ]) -> T :
508+ return await v .__anext__ ()
509+
510+
497511class EageriseBoostable (Boostable [T ]):
498512 def __init__ (self , iterable : AsyncIterator [T ], executor : BoostExecutor ) -> None :
499513 super ().__init__ (executor )
@@ -544,7 +558,7 @@ async def eagerly_buffer(self) -> None:
544558 # We can't use async for because we need to preserve exceptions
545559 it = self .iterable .__aiter__ ()
546560 while True :
547- task = asyncio .create_task (it . __anext__ ( ))
561+ task = asyncio .create_task (anext_cr ( it ))
548562 try :
549563 await task
550564 except StopAsyncIteration :
You can’t perform that action at this time.
0 commit comments