Skip to content

Commit 90758c0

Browse files
committed
Clarify generator, generator function, and generator iterator in glossary
1 parent 57d4446 commit 90758c0

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

Doc/glossary.rst

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -641,23 +641,35 @@ Glossary
641641
.. index:: single: generator
642642

643643
generator
644-
A function which returns a :term:`generator iterator`. It looks like a
645-
normal function except that it contains :keyword:`yield` expressions
646-
for producing a series of values usable in a for-loop or that can be
647-
retrieved one at a time with the :func:`next` function.
644+
An :term:`iterator` object created by a :term:`generator function` or
645+
a :term:`generator expression`.
646+
647+
Usually refers to a generator iterator object, but in some contexts
648+
may refer to a :term:`generator function`. In cases where the
649+
intended meaning isn't clear, using the full terms avoids ambiguity.
648650

649-
Usually refers to a generator function, but may refer to a
650-
*generator iterator* in some contexts. In cases where the intended
651-
meaning isn't clear, using the full terms avoids ambiguity.
651+
.. index:: single: generator function
652+
653+
generator function
654+
A function which returns a :term:`generator` object. It looks like a
655+
normal function except that it contains :keyword:`yield` expressions
656+
for producing a series of values usable in a :keyword:`for`\-loop or
657+
that can be retrieved one at a time with the :func:`next` function.
658+
See :pep:`255`.
652659

653660
generator iterator
654-
An object created by a :term:`generator` function.
661+
An object created by a :term:`generator function` or a
662+
:term:`generator expression`.
655663

656664
Each :keyword:`yield` temporarily suspends processing, remembering the
657-
execution state (including local variables and pending
658-
try-statements). When the *generator iterator* resumes, it picks up where
659-
it left off (in contrast to functions which start fresh on every
660-
invocation).
665+
execution state (including local variables and pending try-statements).
666+
When the *generator iterator* resumes, it picks up where it left off
667+
(in contrast to functions which start fresh on every invocation).
668+
669+
Generator iterators also implement the :meth:`~generator.send` method
670+
to send a value into the suspended generator, and the
671+
:meth:`~generator.throw` method to raise an exception at the point
672+
where the generator was paused. See :pep:`342`.
661673

662674
.. index:: single: generator expression
663675

0 commit comments

Comments
 (0)