Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
I asked a question onstackoverflow because I found a strange error while writing code that makes use an async generator function and the built-inanext() function when using a tuple value for thedefault argument ofanext().
One of thestackoverflow answers contains a good analysis and a possible cause of the problem.
The failing code is the second line withanext():
importasyncioasyncdefgenerator(it=None):ifitisnotNone:yield (it,it)asyncdefmy_func():# results in a=1 b=1a,b=awaitanext(generator(1), (2,3))# results in no printingasyncfora,bingenerator():print(a,b)# raises exceptiona,b=awaitanext(generator(), (2,3))loop=asyncio.new_event_loop()loop.run_until_complete(my_func())
It raises this unexpected exception:
StopAsyncIterationThe above exception was the direct cause of the following exception:Traceback (most recent call last): File"<stdin>", line 1,in<module> File"/Users/manuel/.pyenv/versions/3.12.0/lib/python3.12/asyncio/base_events.py", line 664,in run_until_completereturnfuture.result() ^^^^^^^^^^^^^^^ File"<stdin>", line 6,in my_funcSystemError:<class'StopIteration'> returned a result with an exceptionset
CPython versions tested on:
3.11, 3.12, 3.13
Operating systems tested on:
macOS
Linked PRs
- gh-128078: Clear exception in
anextbefore calling_PyGen_SetStopIterationValue#128780 - [3.12] gh-128078: Clear exception in
anextbefore calling_PyGen_SetStopIterationValue(GH-128780) #128784 - [3.13] gh-128078: Clear exception in
anextbefore calling_PyGen_SetStopIterationValue(GH-128780) #128785 - gh-128078: Simplify logic in
_PyGen_SetStopIterationValue(follow-up to gh-128780) #128287 - [3.13] gh-128078: Use
PyErr_SetRaisedExceptionin_PyGen_SetStopIterationValue(GH-128287) #128789 - [3.12] gh-128078: Use
PyErr_SetRaisedExceptionin_PyGen_SetStopIterationValue(GH-128287) #128790