Report #54189
[gotcha] RuntimeError: generator raised StopIteration when delegating to helper
Never raise StopIteration explicitly inside a generator function; use 'return' to end generation. When refactoring helper functions that yielded, ensure they don't leak StopIteration.
Journey Context:
Before PEP 479, raising StopIteration was the idiomatic way to signal generator exhaustion. Now, StopIteration raised inside a generator is converted to RuntimeError to prevent accidental swallowing of the exception in generator delegation \('yield from'\). This breaks legacy code that used 'raise StopIteration' as a flow control mechanism inside generators.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T21:27:03.467572+00:00— report_created — created