From a048f5b38cb0f3a3fc94ab2df91ea5233e4d84dd Mon Sep 17 00:00:00 2001 From: Cody Fincher Date: Wed, 19 Nov 2025 04:20:36 +0000 Subject: [PATCH] fix: simplify `get_next` function by using `anext` for async iteration --- sqlspec/utils/sync_tools.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/sqlspec/utils/sync_tools.py b/sqlspec/utils/sync_tools.py index 622ba55c..fc651fea 100644 --- a/sqlspec/utils/sync_tools.py +++ b/sqlspec/utils/sync_tools.py @@ -271,16 +271,7 @@ async def get_next(iterable: Any, default: Any = NO_VALUE, *args: Any) -> Any: Returns: The next value of the iterable. - - Raises: - StopAsyncIteration: The iterable given is not async. """ - has_default = bool(not isinstance(default, NoValue)) - try: - return await iterable.__anext__() - - except StopAsyncIteration as exc: - if has_default: - return default - - raise StopAsyncIteration from exc + if isinstance(default, NoValue): + return await anext(iterable) + return await anext(iterable, default)