On Wed, Sep 7, 2016 at 2:31 PM, Nick Coghlan <ncogh...@gmail.com> wrote: > On 4 September 2016 at 09:31, Yury Selivanov <yselivanov...@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] >
I agree this would be better, but the difference compared to PEP-492 async for loops (and even async with statements) would be awful :S. -- Koos > 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 | ncogh...@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/ -- + Koos Zevenhoven + http://twitter.com/k7hoven + _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/