[Python-ideas] PEP 530: Asynchronous Comprehensions
Yury Selivanov
yselivanov.ml at gmail.com
Mon Sep 5 21:16:08 EDT 2016
Hi Sven,
On 2016-09-05 4:27 PM, Sven R. Kunze wrote:
> Hi Yury,
>
> just for my understanding:
>
> On 04.09.2016 01:31, Yury Selivanov wrote:
>> We propose to allow the use of ``await`` expressions in both
>> asynchronous and synchronous comprehensions::
>>
>> result = [await fun() for fun in funcs]
>> result = {await fun() for fun in funcs}
>> result = {fun: await fun() for fun in funcs}
>>
>
> This will produce normal lists, sets and dicts, right?
Right.
>
> Whereas the following will produce some sort of async lists, sets, and
> dicts?
>
>> result = [await fun() async for fun in funcs]
>> result = {await fun() async for fun in funcs}
>> result = {fun: await fun() async for fun in funcs}
>
> If so, how do I read values from an async list/set/dict?
Consider "funcs" to be an asynchronous generator/iterable that produces
a sequence of awaitables. The above comprehensions will await on each
awaitable in funcs, producing regular list, set, and dict.
I doubt that anybody ever would write something like that; this is just
examples of what the PEP will enable.
There is no concept of asynchronous datastructures in Python.
Thanks,
Yury
>
> Sven
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas
mailing list