classification
Title: Mixing yield and return with value is allowed
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.6, Python 3.3, Python 3.4, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: untitaker, vstinner, xiang.zhang
Priority: normal Keywords:

Created on 2016-09-29 09:02 by untitaker, last changed 2016-09-29 10:34 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
lol.py untitaker, 2016-09-29 09:02
Messages (3)
msg277691 - (view) Author: Markus Unterwaditzer (untitaker) Date: 2016-09-29 09:02
The attached example code raises a SyntaxError in Python 2, but is syntactically valid in Python 3. The return value is ignored and an empty generator is produced. I see no reason for this behavioral change.
msg277696 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-09-29 10:22
`return value` is allowed in a generator to support `yield from'. You can read https://www.python.org/dev/peps/pep-0380 for the entire story.
msg277698 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-09-29 10:34
> The return value is ignored and an empty generator is produced.

It's not ignored: it is passed in the argument of the StopIterator object.

> You can read https://www.python.org/dev/peps/pep-0380 for the entire story.

See also the PEP 479 (Change StopIteration handling inside generators) and PEP 492 (Coroutines with async and await syntax).

In short, it's a nice Python 3 feature, not a bug ;-)
History
Date User Action Args
2016-09-29 10:34:48vstinnersetnosy: + vstinner
messages: + msg277698
2016-09-29 10:22:52xiang.zhangsetstatus: open -> closed

nosy: + xiang.zhang
messages: + msg277696

resolution: not a bug
stage: resolved
2016-09-29 09:02:10untitakercreate