async enumeration - possible?

Frank Millman frank at chagford.com
Wed Nov 30 04:14:19 EST 2016


"Ian Kelly"  wrote in message 
news:CALwzid=HriJTV4P1_6FRKQUb25-O1i8oUQuxOzd+auJGL7+LRw at mail.gmail.com...
>
> On Wed, Nov 30, 2016 at 1:29 AM, Frank Millman <frank at chagford.com> wrote:
> >
> > async def anext(aiter):
> >    return await aiter.__anext__()
>
> Even simpler:
>
> def anext(aiter):
>     return aiter.__anext__()
>
> As a general rule, if the only await in a coroutine is immediately
> prior to the return, then it doesn't need to be a coroutine. Just
> return the thing it's awaiting so that the caller can be rid of the
> middle man and await it directly.

Fascinating!

Now I will have to go through all my code looking for similar occurrences. I 
am sure I will find some!

Frank





More information about the Python-list mailing list