[Python-ideas] async/await in Python

Steven D'Aprano steve at pearwood.info
Sun Apr 19 16:01:38 CEST 2015


On Sat, Apr 18, 2015 at 09:55:45PM -0700, Andrew Barnert wrote:

> > The only problem is that, when it's important to specify that you 
> > mean the new kind of coroutines explicitly, there's no obvious way 
> > to do so--if I say "async coroutines" someone may reasonably think 
> > I'm referring to "coroutines as user in asyncio".
> 
> Actually, to answer my question: I could just say "new-style coroutine".
> 
> When I say "new-style class", novices aren't confused by that, and 
> they get the idea that these are probably the kind of class they want; 
> experts have already learned what it means; people in between can look 
> it up easily enough if it's relevant.

-1 on "new-style". New-style classes have been around since Python 2.3 
in 2003, which is twelve years ago. In what way are they still "new"?

At least with new-style classes, the plan always was to deprecate 
classic classes, and in Python 3 the distinction is gone and "type" and 
"class" are, at least, synonyms. But here I understand that the 
generator-based coroutines and the async-def syntax coroutines will 
coexist forever. When Python is 40+ years old, will anyone care that 
generator-based coroutines were added a few releases before async-def 
coroutines?


> And of course it's obvious how to shorten "new-style class" when the 
> difference isn't relevant to the discussion: you just say "class" 
> (maybe with an asterisk saying "new-style, of course", but usually 
> without even needing that).

That doesn't apply here. New-style classes and classic classes are 
*almost* the same. The differences are subtle. But the differences 
between generator-based and async-def coroutines are quite considerable. 
Let's see if I have them all...

Generator-based:
- must use `yield` as an expression;
- cannot use `await`; (?)
- must be declared with a plain `def`;
- must be primed before use;
- use the send() method;

Async-def:
- must not use `yield` or `yield from`;
- may use `await`; (?)
- must be declared with `async def`;
- don't need priming;
- the send() method isn't used; (?)

Apart from the underlying technology, they are nothing alike.

Earlier, with my tongue planted firmly in my cheek, I suggested 
"pyroutines" as a pun on "goroutines" (which is of course a pun on 
coroutines). Silly as that was, I'd rather it than enshrine "new-style" 
and "old-style" again.



-- 
Steve


More information about the Python-ideas mailing list