Spencer Baugh <sba...@catern.com> added the comment:
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 @contextlib.asynccontextmanager async def acm(): # GeneratorExit athrown here from AsyncContextManager __aexit__, # propagated from the body of the contextmanager in func() yield @types.coroutine def _yield(): 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. ---------- nosy: +catern _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35409> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com