Skip to content

Commit 4b53261

Browse files
authored
fix: simplify get_next function by using anext for async iteration (#257)
The previous implementation was using an implementation that was originally 3.9 compatible. There was no `anext` in 3.9. There's also a segfault that's been occurring and moving to `anext` solves it.
1 parent 25b68aa commit 4b53261

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

sqlspec/utils/sync_tools.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,7 @@ async def get_next(iterable: Any, default: Any = NO_VALUE, *args: Any) -> Any:
271271
272272
Returns:
273273
The next value of the iterable.
274-
275-
Raises:
276-
StopAsyncIteration: The iterable given is not async.
277274
"""
278-
has_default = bool(not isinstance(default, NoValue))
279-
try:
280-
return await iterable.__anext__()
281-
282-
except StopAsyncIteration as exc:
283-
if has_default:
284-
return default
285-
286-
raise StopAsyncIteration from exc
275+
if isinstance(default, NoValue):
276+
return await anext(iterable)
277+
return await anext(iterable, default)

0 commit comments

Comments
 (0)