Skip to content

Add typing.Generator #642

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

Closed
JukkaL opened this issue Apr 17, 2015 · 5 comments
Closed

Add typing.Generator #642

JukkaL opened this issue Apr 17, 2015 · 5 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 17, 2015

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

@spkersten
Copy link
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?

@JukkaL
Copy link
Collaborator Author

JukkaL commented May 3, 2015

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.

@gvanrossum
Copy link
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().)

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 14, 2016

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

@gvanrossum
Copy link
Member

Also closed by #1128.

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

No branches or pull requests

3 participants