mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
PEP 479: Change StopIteration handling inside generators.
Closes issue #22906.
This commit is contained in:
parent
bd60e8dece
commit
8170e8c0d1
14 changed files with 103 additions and 15 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue