Report #5672
[gotcha] Generator raises RuntimeError instead of StopIteration when delegating to sub-iterator
Use 'yield from' to delegate to sub-iterators; never let StopIteration bubble up from an explicit next\(\) call inside a generator. Wrap manual next\(\) calls in try/except StopIteration.
Journey Context:
Before PEP 479, raising StopIteration inside a generator simply stopped it. Now it raises RuntimeError. This breaks the pattern of writing helper generators that manually call next\(sub\_iterator\) and let StopIteration propagate. 'yield from' is the correct delegation mechanism because it handles StopIteration internally without exposing it to the containing generator's exception handling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:51:04.635609+00:00— report_created — created