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.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/E2J4FTVGOZDQCBN2SZSY6VTWF2GE4EKK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to