Report #87802
[gotcha] StopIteration raised inside generator is converted to RuntimeError \(PEP 479\)
Never raise StopIteration manually inside a generator; use return to exit. When wrapping iterators, catch StopIteration and return instead of re-raising it.
Journey Context:
Before Python 3.7, manually raising StopIteration inside a generator would silently end it, which caused subtle bugs when refactoring iterator wrappers. PEP 479 changed this so that StopIteration raised inside a generator is converted to RuntimeError, breaking legacy code. The correct pattern is to let the generator exhaust naturally or use return, which raises the proper StopIteration automatically.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:57:42.254763+00:00— report_created — created