Skip to content

Generalize yield statement function type #1128

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

Merged
merged 3 commits into from
Jan 15, 2016
Merged

Conversation

ddfisher
Copy link
Collaborator

Functions containing yield statements can now return any supertype
of generator. This fixes #1011.

In making this pull request, I noticed that the allowed return types of functions containing yields are different depending on whether or not the yield is a statement, expression, or a yield from. I'll make a PR to make them all behave consistently next.

Functions containing yield statements can now return any supertype
of generator. This fixes python#1011.
@@ -30,7 +30,7 @@
INVALID_EXCEPTION = 'Exception must be derived from BaseException'
INVALID_EXCEPTION_TYPE = 'Exception type must be derived from BaseException'
INVALID_RETURN_TYPE_FOR_YIELD = \
'Iterator function return type expected for "yield"'
'Generator or supertype function return type expected for "yield"'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence sounds a bit odd. Maybe we can throw it around, e.g.

The return type of a generator function should be "Generator" or a supertype thereof.

(The mention of "yield" in the original message is kind of a distraction -- the problem is not with the yield statement/expression but with the function's type declaration. Extra points if you can find the line number of the 'def' line.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree -- that rephrasing is much better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any clear way of setting the error message line to point to the function def, though...

@gvanrossum
Copy link
Member

LGTM except for the phrasing of the error message.

I'm looking forward to seeing the other issue fixed too!

@@ -30,7 +30,7 @@
INVALID_EXCEPTION = 'Exception must be derived from BaseException'
INVALID_EXCEPTION_TYPE = 'Exception type must be derived from BaseException'
INVALID_RETURN_TYPE_FOR_YIELD = \
'Iterator function return type expected for "yield"'
'The return type of a generator function should be "Generator" or a supertype thereof'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about "or one of its supertypes"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's even clearer. Thanks!

gvanrossum added a commit that referenced this pull request Jan 15, 2016
Generalize yield statement function type
@gvanrossum gvanrossum merged commit ccdbeab into python:master Jan 15, 2016
@gvanrossum gvanrossum mentioned this pull request Jan 15, 2016
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

Successfully merging this pull request may close these issues.

Need to add Generator support
3 participants