Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shouldn't typing also have Coroutine? #251

Closed
gvanrossum opened this issue Jul 22, 2016 · 8 comments
Closed

Shouldn't typing also have Coroutine? #251

gvanrossum opened this issue Jul 22, 2016 · 8 comments
Milestone

Comments

@gvanrossum
Copy link
Member

PEP 492 introduces a few new ABCs: Awaitable, Coroutine, AsyncIterable, AsyncIterator. PEP 484 lists three of these: Awaitable, AsyncIterable, AsyncIterator. What happened to Coroutine? A Coroutine is an Awaitable that also supports send(), throw() and close().

It seems a simple oversight. Let's fix it before 3.5.3 comes out.

@1st1 do you remember any of this? Do you recall a reason to leave out Coroutine?

@1st1
Copy link
Member

1st1 commented Jul 22, 2016

@1st1 do you remember any of this? Do you recall a reason to leave out Coroutine?

No, I suspect it was left out by mistake.

@gvanrossum
Copy link
Member Author

gvanrossum commented Jul 22, 2016 via email

@gvanrossum gvanrossum modified the milestone: 3.5.3 Aug 26, 2016
@thehesiod
Copy link

thehesiod commented Oct 24, 2016

it would be neat if we could specify the parameters to the coroutine as well...something like:

async def dummy(dummy_param: int) -> Awaitable[None]:
    return

async needs_typing(co_method: Coroutine[int]):
    await co_method(1)

await needs_typing(dummy)

I just realized a super neat thing would be also being able to specify the return type of co_method parameter like Callable If it were possible something like:

async needs_typing(co_method: Coroutine[[int], None]):
    await co_method(1)
  • updated based on new understanding of existing typing.Callable

@ilevkivskyi
Copy link
Member

@gvanrossum
I see that you have assigned this issue to yourself, but if you don't mind, I would like to do this (in python/typing and in python/peps). Just a small clarification: should order of type variables be the same as for Generator? So that:

class Coroutine(Awaitable[ret_type_co], Generic[yield_type_co, send_type_contra, ret_type_co]):
    ...

@gvanrossum
Copy link
Member Author

gvanrossum commented Oct 29, 2016 via email

@ilevkivskyi
Copy link
Member

In principle a normal coroutine defined with async def has a trivial .send() method that only accepts None and raises StopIteration. However, one could make a coroutine "manually" by instantiating a non-abstract subclass of collections.abc.Coroutine. Such "manually created" coroutine could have a non-trivial .send() method. But I agree with you that this use case is probably rare. I do not have a preference here. @1st1 what do you think?

@ilevkivskyi
Copy link
Member

@gvanrossum Yet another option would be to make Coroutie a special form. So that Coroutine[[X, Y], Z] is essentially equivalent to Callable [[X, Y], Awaitable[Z].

@gvanrossum
Copy link
Member Author

Oh, no! I think after all it should indeed mimic Generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants