-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed as not planned
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Description
Bug report
Bug description:
def y1(*args):
return args
def y2(*args):
return args
yield 3
print("y1: " + str(list(y1(1, 2, 3, 4))))
print("y2: " + str(list(y2(1, 2, 3, 4))))
While the yield
in y2
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 immediate StopIteration
error with args
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 a None
argument, this signals the basic case where a Generator is returning an empty iterator.
Consider throwing RuntimeError
when StopIteration
is raised with a non-None
valued error when calling next
to prevent this confusing behaviour.
CPython versions tested on:
3.10
Operating systems tested on:
macOS
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement