Skip to content

Generalize yield statement function type - #1128

Merged
gvanrossum merged 3 commits into
python:masterfrom
ddfisher:master
Jan 15, 2016
Merged

gvanrossum merged 3 commits into
python:masterfrom
ddfisher:master

Conversation

@ddfisher

Copy link
Copy Markdown
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.
Comment thread mypy/messages.py Outdated

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

LGTM except for the phrasing of the error message.

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

Comment thread mypy/messages.py Outdated

Copy link
Copy Markdown
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
Copy Markdown
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