New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Silent StopIteration exc when raised from generator inside of another generator #60814
Comments
def emptygen():
# Or other more meaningful generator
raise StopIteration
yield
def wrap(gen):
next(gen)
print("This should be printed or StopIteration raised.")
while True:
try:
yield next(gen)
except StopIteration as exc:
return
items = wrap(emptygen())
for item in items:
print(item)
print("End.") |
I don't see the bug here. Your for loop calls wrap. Wrap calls emptygen. Emptygen raises a StopIteration exception. That exception is of course propagated upward (it isn't caught by wrap), and the loop stops. |
OK, thanks for explanation. The behaviour is still strange, because when I delete try...except clause On Tue, Dec 4, 2012 at 9:14 PM, R. David Murray <report@bugs.python.org>wrote:
|
The only way I was able to replicate that result was by removing the entire try/except block, including the yield. In that case, wrap is no longer a generator, so the exception is raised before you enter the for loop. |
Thank you, I wasn't paying attention enough. It works as you describe. On Tue, Dec 4, 2012 at 9:46 PM, R. David Murray <report@bugs.python.org>wrote:
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: