This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author catern
Recipients Roman.Evstifeev, catern, miss-islington, vxgmichel
Date 2020-08-29.20:32:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I'm not sure this was the correct fix - or at least, this creates further issues with asynccontextmanager. Consider the following code:

import contextlib
import types

async def acm():
    # GeneratorExit athrown here from AsyncContextManager __aexit__,
    # propagated from the body of the contextmanager in func()

def _yield():

async def func():
    async with acm():
        # GeneratorExit raised here
        await _yield()

x = func()
x.send(None) # start running func
x.close() # raise GeneratorExit in func at its current yield
# AsyncContextManager __aexit__ fails with "RuntimeError: generator didn't stop after throw()"

The reason for the failure in AsyncContextManager __aexit__ is that the asyncgenerator raises StopIteration instead of GeneratorExit when agen.athrow(GeneratorExit()) is called and driven, so "await agen.athrow(GeneratorExit())" just evaluates to None, rather than raising GeneratorExit.

On 3.6 this would work fine, because "await athrow(GeneratorExit())" will raise GeneratorExit. I suspect this was broken by this change.
Date User Action Args
2020-08-29 20:32:23caternsetrecipients: + catern, Roman.Evstifeev, vxgmichel, miss-islington
2020-08-29 20:32:23caternsetmessageid: <>
2020-08-29 20:32:23caternlinkissue35409 messages
2020-08-29 20:32:23caterncreate