Skip to content

Make the 2 last parameters for typing.Generator optional #4221

Closed

Description

@sametmax

If I use:

Generator[int]

mypy complains:

error: "Generator" expects 3 type arguments, but 1 given

I can silence mypy by doing:

Generator[int, None, None]

But given that the majority of generators just yield, rarely return or send, I think it would make sense to allow the last 2 parameters to have a default value of None.

Activity

  1. emmatyping commented on Nov 8, 2017

    @emmatyping
    Member

    This issue is probably better suited to be discussed in the typing repo https://github.com/python/typing

  2. JukkaL commented on Nov 8, 2017

    @JukkaL
    Collaborator

    Is there a reason you can't use Iterator[int] as the return type?

  3. zeth commented on Dec 1, 2021

    @zeth

    Is there a reason you can't use Iterator[int] as the return type?

    Because the type is a Generator. Are we annotating the types or not?

  4. hauntsaninja commented on Dec 1, 2021

    @hauntsaninja
    Collaborator

    We are annotating the types, all three of them, yield send and return ;-) For everything else, there's Iterator.

    While I don't think this is a compelling case since there's a solution that works perfectly well, I'm sympathetic to the idea of defaults for generic types in general. The forum to take that issue up is the typing-sig mailing list or https://github.com/python/typing, not here

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions