Skip to content

Commit eb525ca

Browse files
authored
support Awaitable .__anext__
see python/typeshed#7491 (comment)
1 parent 47c1e0e commit eb525ca

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

boostedblob/boost.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
import sys
45
from typing import (
56
Any,
67
AsyncIterable,
@@ -18,8 +19,12 @@
1819
Type,
1920
TypeVar,
2021
Union,
22+
TYPE_CHECKING,
2123
)
2224

25+
if TYPE_CHECKING:
26+
from _typeshed import SupportsAnext
27+
2328
A = TypeVar("A")
2429
T = TypeVar("T")
2530
R = 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+
497511
class 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:

0 commit comments

Comments
 (0)