Skip to content

Shouldn't typing also have Coroutine? #251

Closed

Description

@gvanrossum

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?

Activity

  1. 1st1 commented on Jul 22, 2016

    @1st1
    Member

    @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.

  2. gvanrossum commented on Jul 22, 2016

    @gvanrossum
    MemberAuthor
  3. modified the milestone: 3.5.3 on Aug 26, 2016
  4. thehesiod commented on Oct 24, 2016

    @thehesiod

    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
  5. ilevkivskyi commented on Oct 29, 2016

    @ilevkivskyi
    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]):
        ...
  6. gvanrossum commented on Oct 29, 2016

    @gvanrossum
    MemberAuthor
  7. ilevkivskyi commented on Oct 29, 2016

    @ilevkivskyi
    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?

  8. ilevkivskyi commented on Oct 29, 2016

    @ilevkivskyi
    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].

  9. gvanrossum commented on Oct 29, 2016

    @gvanrossum
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions