Issue 28310: Mixing yield and return with value is allowed (original) (raw)

Issue28310

Created on 2016-09-29 09:02 by untitaker, last changed 2022-04-11 14:58 by admin. 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
2022-04-11 14:58:37 admin set github: 72497
2016-09-29 10:34:48 vstinner set nosy: + vstinnermessages: +
2016-09-29 10:22:52 xiang.zhang set status: open -> closednosy: + xiang.zhangmessages: + resolution: not a bugstage: resolved
2016-09-29 09:02:10 untitaker create