New submission from Bryan Koch <bbkoc...@gmail.com>:

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 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.  If StopIteration.value is meant to represent the final value, then the 
built-in for-loop should not skip it and the current implementation in 3.3, 
3.4, 3.5, and 3.6 should be considered an oversight of the PEP and a bug (I 
don't have a version of 3.7 or 3.8 to test newer versions).

Reproduction code is attached with comments/annotations.

----------
files: ex1.py
messages: 333802
nosy: Bryan Koch
priority: normal
severity: normal
status: open
title: Using `return value` in a generator function skips the returned value on 
for-loop iteration
type: behavior
versions: Python 3.4, Python 3.5, Python 3.6
Added file: https://bugs.python.org/file48062/ex1.py

_______________________________________
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

Reply via email to