File tree 1 file changed +15
-1
lines changed 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
import asyncio
4
+ import sys
4
5
from typing import (
5
6
Any ,
6
7
AsyncIterable ,
18
19
Type ,
19
20
TypeVar ,
20
21
Union ,
22
+ TYPE_CHECKING ,
21
23
)
22
24
25
+ if TYPE_CHECKING :
26
+ from _typeshed import SupportsAnext
27
+
23
28
A = TypeVar ("A" )
24
29
T = TypeVar ("T" )
25
30
R = TypeVar ("R" )
@@ -494,6 +499,15 @@ async def blocking_dequeue(self) -> Tuple[int, T]:
494
499
return ret
495
500
496
501
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
+
497
511
class EageriseBoostable (Boostable [T ]):
498
512
def __init__ (self , iterable : AsyncIterator [T ], executor : BoostExecutor ) -> None :
499
513
super ().__init__ (executor )
@@ -544,7 +558,7 @@ async def eagerly_buffer(self) -> None:
544
558
# We can't use async for because we need to preserve exceptions
545
559
it = self .iterable .__aiter__ ()
546
560
while True :
547
- task = asyncio .create_task (it . __anext__ ( ))
561
+ task = asyncio .create_task (anext_cr ( it ))
548
562
try :
549
563
await task
550
564
except StopAsyncIteration :
You can’t perform that action at this time.
0 commit comments