<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Apr 17, 2015 at 5:21 PM, Greg Ewing <span dir="ltr"><<a href="mailto:greg.ewing@canterbury.ac.nz" target="_blank">greg.ewing@canterbury.ac.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Yury Selivanov wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Here's my proposal to add async/await in Python.<br>
</blockquote>
<br></span>
You've essentially reinvented PEP 3152 - Cofunctions.<br>
<br>
<a href="https://www.python.org/dev/peps/pep-3152/" target="_blank">https://www.python.org/dev/peps/pep-3152/</a><br></blockquote><div><br></div><div>I *thought* Yury's proposal sounded familiar! :-)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Here's a summary of the relationships between them:<br>
<br>
PEP 3152                  Nearest equivalent in Yury's PEP<br>
--------                  --------------------------------<br>
<br>
codef f(args):            async def f(args):<br>
<br>
cocall f(args)            await f(args)<br>
<br>
__cocall__                __await__<br>
<br>
costart()                 async_def()<br>
<br>
There is currently no equivalent of "async for" and<br>
"async with" in PEP 3152, but they could easily be added.<br>
I would probably spell them "cofor" and "cowith".<br></blockquote><div><br></div><div>Unfortunately that's a lot of new reserved words, and they aren't even words. :-) I like the elegance of Yury's idea of prefixing various statements with "async". It also happens to easy introduction, since the lexer can be adapted (for a few releases at least) not to treat "async" as a reserved word unless followed by "def" etc.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As the author of PEP 3152 I'm obviously biased, but I<br>
think my spellings are more elegant and less disruptive<br>
to reading of the code.<br></blockquote><div><br></div><div>As the BDFL I'm perhaps also biased (Yury went over early stages of his draft with me at PyCon) but I prefer his spellings.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
PEP 3152 is currently marked as deferred. Maybe it's<br>
time to revive it? If Yury's pep is to be considered,<br>
we ought to discuss the relative merits of the two.<span class="HOEnZb"><font color="#888888"></font></span></blockquote><div><br></div><div> I wonder if, instead of putting forward a competing proposal that is so similar, you could help Yury with PEP 492? I'm sure he'd happily take you as a co-author.<br><br></div><div>I have one question about PEP 3152. IIUC, it states that cofunctions cannot be called except using cocall, and there seems to be syntax that enforces that the "argument" to cocall looks like a function call. This would rule out things that are normally always allowed in Python, if you have<br>```<br></div><div>return foo(args)<br>```<br></div><div>you can replace that with<br>```<br></div><div>r = foo(args)<br></div><div>return r<br>```<br></div><div>But the way I read PEP 3152 the call has to occur syntactically in the cocall form, so<br>```<br></div><div>cocall foo(args)<br>```<br></div><div>cannot be replaced with<br>```<br></div><div>x = foo(args)<br></div><div>cocall x<br>```<br></div><div>This ability is occasionally useful in asyncio, for example when creating a task, we can write<br>```<br></div><div>x = Task(foo(args))<br>```<br></div><div>and then someone else can write<br></div><div>```</div><div>yield from x<br>```<br></div></div>Your cocall syntax is lacking such ability, since cocall insist on call syntax ("cocall x" is a syntax error). It would seem that in general your cocall is not a substitution for yield from when used with a future or task, and that looks like a real deficiency to me.<br></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>