Files
cpython/Python/clinic
Serhiy StorchakaandClaude Opus 5 1620e0f1b5 gh-64862: Add the stop_exception parameter in iter() and aiter() (GH-156298)
The iteration stops when the callable raises the specified exception (an
exception class or a tuple of exception classes).  It is keyword-only and
can be used without the stop value.  The second parameter of iter() is now
named stop_value and can be passed as a keyword argument.

aiter() now accepts the same parameters, which it never had before: the
callable is called and its result is awaited for every __anext__().

If the callable raises StopIteration (StopAsyncIteration in aiter()) which
does not match stop_exception, it is replaced with RuntimeError, as PEP 479
and PEP 525 do for generators.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-01 15:55:32 +03:00
..