py_anext#

langchain_core.utils.aiter.py_anext(iterator: ~typing.AsyncIterator[~langchain_core.utils.aiter.T], default: ~langchain_core.utils.aiter.T | ~typing.Any = <object object>) Awaitable[T | None | Any][source]#

Pure-Python implementation of anext() for testing purposes.

Closely matches the builtin anext() C implementation. Can be used to compare the built-in implementation of the inner coroutines machinery to C-implementation of __anext__() and send() or throw() on the returned generator.

Parameters:
  • iterator (AsyncIterator[T]) – The async iterator to advance.

  • default (T | Any) – The value to return if the iterator is exhausted. If not provided, a StopAsyncIteration exception is raised.

Returns:

The next value from the iterator, or the default value

if the iterator is exhausted.

Raises:

TypeError – If the iterator is not an async iterator.

Return type:

Awaitable[T | None | Any]