On Wed, Sep 7, 2016 at 2:31 PM Nick Coghlan <ncoghlan@gmail.com> wrote:
On 4 September 2016 at 09:31, Yury Selivanov <yselivanov.ml@gmail.com> wrote:
> With the proposed asynchronous comprehensions syntax, the above code
> becomes as short as::
>
>     result = [i async for i in aiter() if i % 2]

After using it a few times in examples, while I'm prepared to accept
the agrammatical nature of "async for" in the statement form (where
the adjective-noun phrase can be read as a kind of compound noun
introducing the whole statement), I think for the comprehension form,
we should aim to put the words in the right grammatical order if we
can:

    result = [i for i in async aiter() if i % 2]

Please, no.
It may be totally correct from English grammar POV but brings different syntax from regular async for statement, e.g.
async for row in db.execute(...):
    pass
Currently regular comprehensions are pretty similar to `for` loop.

Why async comprehensions should look different from `async for` counterpart?
 
I think the readability gain from that approach becomes even clearer
with nested loops:

    result = [x for aiterable in async outer() for x in async aiterable]

vs the current:

    result = [x async for aiterable in outer() async for x in async aiterable]

In the first form, "async" is clearly a pre-qualifier on "outer()" and
"aiterable", indicating they need to be asynchronous iterators rather
than synchronous ones.

By contrast, in the current form, the first "async" reads like a
post-qualifer on "x" (it isn't, it modifies how outer() is handled in
the outer loop), while the second looks like a post-qualifier on
"outer()" (it isn't, it modified how aiterable is handled in the inner
loop)

If that means having to postpone full async comprehensions until
"async" becomes a proper keyword in 3.7 and only adding "await in
comprehensions and generator expressions" support to 3.6, that seems
reasonable to me

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
--
Thanks,
Andrew Svetlov