stop-iteration-return (PLR1708)
Preview (since 0.14.3) · Related issues · View source
Derived from the Pylint linter.
This rule is unstable and in preview. The --preview flag is required for use.
What it does
Checks for explicit raise StopIteration in generator functions.
Why is this bad?
Raising StopIteration in a generator function causes a RuntimeError
when the generator is iterated over.
Instead of raise StopIteration, use return in generator functions.
Example
Use instead: