[Python-ideas] Async API: some code to review
Yury Selivanov
yselivanov.ml at gmail.com
Mon Oct 29 17:59:12 CET 2012
On 2012-10-29, at 12:07 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> In the docstrings I use the prefix "COROUTINE:" to indicate public
>> APIs that should be invoked using yield from.
>
> Hmm, should they? Your approach looks a bit weird: you have functions
> that should use yield, and others that should use "yield from"? That
> sounds confusing to me.
>
> I'd much rather either have all functions use "yield", or have all
> functions use "yield from".
>
> (also, I wouldn't be shocked if coroutines had to wear a special
> decorator; it's a better marker than having the word COROUTINE in the
> docstring, anyway :-))
That's what bothers me is well. 'yield from' looks too long for a
simple thing it does (1); users will be confused whether they should
use 'yield' or 'yield from' (2); there is no visible difference between
a plain generator and a coroutine (3).
Personally, I like Greg's PEP 3152 (aside from 'cocall' keyword).
With that approach it's easy to distinguish coroutines, generators and
plain functions. And it'd be easier to add some special
methods/properties to codefs, like 'in_finally()' method etc.
-
Yury
More information about the Python-ideas
mailing list