Allow return value in asynchronous generator

Currently, asynchronous generators don't allow a non-empty `return` statement: ```python import asyncio async def async_generator(): x = yield 1 await asyncio.sleep(1) if x: ... return "result A" # SyntaxError else: ... return "result B" ``` unlike regular generators which communicate their return value via the `value` attribute on the `StopIteration` exception: ```python def synchronous_generator(): x = yield 1 if x: ... return "result A" # raises StopIteration with value="result A" else: ... return "result B" ``` I think that `StopAsyncIteration` should behave likewise and have a `value` attribute containing the return value. I'm not aware of any reason to maintain this asymmetry.

I guess this can be extended to "allow `yield from` with asynchronous generators", maybe something like `async yield from`.

I guess this can be extended to "allow `yield from` with asynchronous generators", maybe something like `async yield from`.
participants (1)
-
Paolo Lammens