[issue35409] Async generator might re-throw GeneratorExit on aclose()

2020-08-29 Thread Spencer Baugh


Spencer Baugh  added the comment:

My mistake, I see now this is just https://bugs.python.org/issue33786 and is 
already fixed.

--

___
Python tracker 
<https://bugs.python.org/issue35409>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35409] Async generator might re-throw GeneratorExit on aclose()

2020-08-29 Thread Spencer Baugh


Spencer Baugh  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 
<https://bugs.python.org/issue35409>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com