[Python-Dev] Tricky way of of creating a generator via a comprehension expression
Yury Selivanov
yselivanov.ml at gmail.com
Wed Nov 22 11:58:08 EST 2017
On Wed, Nov 22, 2017 at 11:11 AM, Paul Moore <p.f.moore at gmail.com> wrote:
[..]
> But by the logic you just described, await isn't (or shouldn't be)
> allowed, surely?
No, that's a stretch. People can understand and actually use 'yield
(await foo())', but they usually can't figure what 'yield (yield
foo())' actually does:
def foo():
yield (yield 1)
Who on this mailing list can meaningfully use the 'foo()' generator?
async def bar():
yield (await foo())
'bar()' is perfectly usable in an 'async for' statement and it's easy
to understand what it does if you spend an hour writing async/await
code.
Yury
More information about the Python-Dev
mailing list