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

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

Closed
sametmax opened this issue Nov 8, 2017 · 4 comments
Closed

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

sametmax opened this issue Nov 8, 2017 · 4 comments

Comments

@sametmax
Copy link

sametmax commented Nov 8, 2017

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.

@emmatyping
Copy link
Collaborator

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

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 8, 2017

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

@zeth
Copy link

zeth commented Dec 1, 2021

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?

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Dec 1, 2021

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants