Repository navigation
Generalize yield statement function type - #1128
Conversation
Functions containing yield statements can now return any supertype of generator. This fixes python#1011.
There was a problem hiding this comment.
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.
I agree -- that rephrasing is much better.
There was a problem hiding this comment.
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! |
There was a problem hiding this comment.
What about "or one of its supertypes"?
There was a problem hiding this comment.
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
yields are different depending on whether or not theyieldis a statement, expression, or ayield from. I'll make a PR to make them all behave consistently next.