bryan.koch <bbkoc...@gmail.com> added the comment:
I understood the PEP to include `return expr` in the iteration values as per the first bullet of the proposal. > Any values that the iterator yields are passed directly to the caller. This bullet doesn't have any additional formatting on the word "yields" so I consider it as not directly referring to the "yield" keyword. With the current implementation, I have to concern myself if a generator function was created with the intention of being called using `last_ret = yield from function(); yield last_ret` or as `for ret in function(): yield ret`. The first also yields the return value but would also yield an additional `None` if a `return` was not the terminal cause; the second will miss the last value if the generator uses `return`. Essentially, allowing `return expr` in generator functions without invoking the generator using `yield from generator` will lose the last value. I support either of the below resolutions: * `return expr` being invoked from a generator that is not being iterated using `yield from generator` is a SyntaxError * `return expr` being invoked from a generator that is not being iterated using `yield from generator` includes the final return value in the iterated set ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35756> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com