Non-None
return value from generator should throw RuntimeError
#127306
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
pending
The issue will be closed if no feedback is provided
type-feature
A feature request or enhancement
Bug report
Bug description:
While the
yield
iny2
is unreachable (this happened to me while re-writing a function and leaving what I thought was dead code at the end), y2 is considered a Generator, and iterating over it produces an immediateStopIteration
error withargs
as the argument, which manifests as an empty iterator.I can't imagine a good reason to create a
StopIteration
exception with a non-None
argument. With aNone
argument, this signals the basic case where a Generator is returning an empty iterator.Consider throwing
RuntimeError
whenStopIteration
is raised with a non-None
valued error when callingnext
to prevent this confusing behaviour.CPython versions tested on:
3.10
Operating systems tested on:
macOS
The text was updated successfully, but these errors were encountered: