-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
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"' |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
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' |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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!
Generalize yield statement function type
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
yield
s are different depending on whether or not theyield
is a statement, expression, or ayield from
. I'll make a PR to make them all behave consistently next.