Skip to content

Add typing.Generator #642

Closed
Closed

Description

@JukkaL

typing.Generator is specified in the PEP 484 draft. Allow it to be used as the return type of a generator function.

Activity

  1. spkersten commented on May 2, 2015

    @spkersten
    Contributor

    I'm trying to implement this (see my generator branch for progress). Should Iterator still be allowed as return type of a function in case Generator's send_type and return_type are None?

  2. JukkaL commented on May 3, 2015

    @JukkaL
    CollaboratorAuthor

    If a function has Generator as the return type, it should not return an Iterator, as Iterator may not have the send and throw methods.

  3. gvanrossum commented on Jan 13, 2016

    @gvanrossum
    Member

    See also #695 and #1011 (at least one of these three is a duplicate).

    FWIW I think Sander's question is whether this is still allowed:

    def foo() -> Iterator[int]:
        yield 0
    

    or whether all generators must be declared as Generator. I believe this example should still be valid (but callers should not call send() or throw().)

  4. JukkaL commented on Jan 14, 2016

    @JukkaL
    CollaboratorAuthor

    Yeah, an Iterator return type should still be fine. I was confused above about the question.

  5. gvanrossum commented on Jan 15, 2016

    @gvanrossum
    Member

    Also closed by #1128.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions