[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-21 Thread Steven D'Aprano
Steven D'Aprano added the comment: > I'm off to write an ugly `next()` wrapper then. Wouldn't it be simpler to re-design the generators to yield the final result instead of returning it? To process the final item differently from the rest, you just need something like this: last = next(it)

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-21 Thread bryan.koch
bryan.koch added the comment: Thanks for testing that. I'm off to write an ugly `next()` wrapper then. -- ___ Python tracker ___

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-21 Thread Steven D'Aprano
Steven D'Aprano added the comment: > steven your generator example is exactly what I wanted to do; looks > like I'm upgrading to Python 3.8 for the new assignment syntax. Sorry to have mislead you, but I don't think it will do what I thought. After giving it some more thought, I decided to

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-21 Thread bryan.koch
bryan.koch added the comment: steven your generator example is exactly what I wanted to do; looks like I'm upgrading to Python 3.8 for the new assignment syntax. I was actually expecting the SyntaxError to be raised at runtime which would be a pretty large behavior change (definitely

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-18 Thread Steven D'Aprano
Steven D'Aprano added the comment: On Fri, Jan 18, 2019 at 12:31:51AM +, bryan.koch wrote: > Thank you both for the clarifications. I agree these's no bug in > `yield from` however is there a way to reference the return value when > a generator with a return is invoked using `for val

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-18 Thread Greg Ewing
Greg Ewing added the comment: bryan.koch wrote: > It would be awesome if invoking a generator above would throw a > SyntaxError iff it contained a return and it wasn't invoked through `yield > from`. Why do you care about that so much? There's nothing to stop you from ignoring the return

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-18 Thread Terry J. Reedy
Terry J. Reedy added the comment: No bug here. You can discuss possible change on python-ideas, but I strongly suggest that you write your next wrapper and move on. -- nosy: +terry.reedy resolution: -> not a bug stage: -> resolved status: open -> closed versions: +Python 3.7

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-17 Thread bryan.koch
bryan.koch added the comment: Thank you both for the clarifications. I agree these's no bug in `yield from` however is there a way to reference the return value when a generator with a return is invoked using `for val in gen` i.e. when the generator is invoked without delegation? I could

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-17 Thread Greg Ewing
Greg Ewing added the comment: There is no bug here; the current implementation is working as intended. The word "yields" in the quoted section of the PEP indeed refers to the "yield" keyword and nothing else. Possibly that could be clarified, but I believe it's already clear enough when

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-16 Thread Steven D'Aprano
Steven D'Aprano 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

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-16 Thread bryan.koch
bryan.koch 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

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-16 Thread Steven D'Aprano
Steven D'Aprano added the comment: You say: > The PEP reads as if returning a value via StopIteration was meant to signal > that the generator was finished and that StopIteration.value was the final > value. To me, the PEP is clear that `return expr` is equivalent to `raise

[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

2019-01-16 Thread Bryan Koch
New submission from Bryan Koch : Using the new "`return value` is semantically equivalent to `raise StopIteration(value)`" syntax created in PEP-380 (https://legacy.python.org/dev/peps/pep-0380/#formal-semantics) causes the returned value to be skipped by standard methods of iteration. The