This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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
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 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit 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 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 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 ;-)
Date User Action Args
2022-04-11 14:58:37adminsetgithub: 72497
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