On 22 November 2017 at 21:07, Yury Selivanov <yselivanov...@gmail.com> wrote:
> On Wed, Nov 22, 2017 at 2:37 PM, Ivan Levkivskyi <levkivs...@gmail.com> > wrote: > > On 22 November 2017 at 20:33, Guido van Rossum <gu...@python.org> wrote: > >> > >> On Wed, Nov 22, 2017 at 11:12 AM, Ivan Levkivskyi <levkivs...@gmail.com > > > >> wrote: > >>> > >>> On 22 November 2017 at 20:05, Guido van Rossum <gu...@python.org> > wrote: > >>>> > >>>> On Wed, Nov 22, 2017 at 10:54 AM, Jelle Zijlstra > >>>> <jelle.zijls...@gmail.com> wrote > >>>>> > >>>>> 2017-11-22 9:58 GMT-08:00 Guido van Rossum <gu...@python.org>: > >>>>> > >>>>> (OTOH, await in the same position must keep working since it's not > >>>>> broken and not unintuitive either.) > >>>> > >>>> > >>> > >>> > >>> This is very questionable IMO. > >>> So do you think that [await x for y in z] and list(await x for y in z) > > Comprehensions are declarative, and that's why [], and {} work with > async/await. When you're using parens () you *explicitly* tell Python > compiler that you want a generator expression. > > And the distinction between comprehensions and generator expressions > also exists for synchronous code: > > x = [a for a in range(10)] > x[0] > > and > > x = (a for a in range(10)) > x[0] # TypeError > > Is the above "intuitive" for all Python users? Probably not. Write > it once, get your TypeError, read the error message and you understand > what's going on here. > > Is the difference between "[await x for y in z ]" and "list(await x > for y in z)" intuitive for all Python users? Again, probably not. > But for those who write async code it is. > Just found another example of intuitive behaviour: >>> async def f(): ... for i in range(3): ... yield i ... >>> async def g(): ... return [(yield i) async for i in f()] ... >>> g().send(None) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 2, in g TypeError: object async_generator can't be used in 'await' expression of course it is obvious for anyone who writes async code, but anyway an interesting example. -- Ivan
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com