On 1 May 2015 at 12:24, Andrew Barnert via Python-ideas <python-ideas@python.org> wrote:
Anyway, if I understand the problem, the main confusion is that we use "coroutine" both to mean a thing that can be suspended and resumed, and a function that returns such a thing. Why not just "coroutine" and "coroutine function", just as with "generator" and "generator function".
That's the terminology in the asyncio docs I guess: https://docs.python.org/3/library/asyncio-task.html#coroutine ... except that there it is referring to decorated generator functions. That feels like a category error to me because coroutines are a generalisation a functions so if anything is the coroutine itself then it is the async def function rather than the object it returns but I guess if that's what's already being used.
If the issue is that there are other things that are coroutines besides the coroutine type... well, there are plenty of things that are iterators that are all of unrelated types, and has anyone ever been confused by that? (Of course people have been confused by iterator vs. iterable, but that's a different issue, and one that doesn't have a parallel here.)
There is no concrete "iterator" type. The use of iterator as a type is explicitly intended to refer to a range of different types of objects analogous to using an interface in Java. The PEP proposes at the same time that the word coroutine should be both a generic term for objects exposing a certain interface and also the term for a specific language construct: the function resulting from an async def statement. So if I say that something is a "coroutine" it's really not clear what that means. It could mean an an asyncio.coroutine generator function, it could mean an async def function or it could mean both. Worse it could mean the object returned by either of those types of functions. -- Oscar