PEP 479: Change StopIteration handling inside generators.

Closes issue #22906.
This commit is contained in:
Yury Selivanov 2015-05-09 11:44:30 -04:00
parent bd60e8dece
commit 8170e8c0d1
14 changed files with 103 additions and 15 deletions

View file

@ -481,10 +481,10 @@ Here's a sample usage of the ``generate_ints()`` generator:
You could equally write ``for i in generate_ints(5)``, or ``a,b,c =
generate_ints(3)``.
Inside a generator function, ``return value`` is semantically equivalent to
``raise StopIteration(value)``. If no value is returned or the bottom of the
function is reached, the procession of values ends and the generator cannot
return any further values.
Inside a generator function, ``return value`` causes ``StopIteration(value)``
to be raised from the :meth:`~generator.__next__` method. Once this happens, or
the bottom of the function is reached, the procession of values ends and the
generator cannot yield any further values.
You could achieve the effect of generators manually by writing your own class
and storing all the local variables of the generator as instance variables. For