Skip to content

Commit 2a77ef7

Browse files
[3.13] gh-150831: docs: clarify generator, generator function, and generator iterator in glossary (GH-150905) (#151841)
gh-150831: docs: clarify generator, generator function, and generator iterator in glossary (GH-150905) (cherry picked from commit 1de86e1) Co-authored-by: Aniket <148300120+Aniketsy@users.noreply.github.com>
1 parent 15f9e62 commit 2a77ef7

1 file changed

Lines changed: 34 additions & 21 deletions

File tree

Doc/glossary.rst

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,24 @@ Glossary
9090
:meth:`~object.__aexit__` methods. Introduced by :pep:`492`.
9191

9292
asynchronous generator
93-
A function which returns an :term:`asynchronous generator iterator`. It
94-
looks like a coroutine function defined with :keyword:`async def` except
95-
that it contains :keyword:`yield` expressions for producing a series of
96-
values usable in an :keyword:`async for` loop.
97-
98-
Usually refers to an asynchronous generator function, but may refer to an
99-
*asynchronous generator iterator* in some contexts. In cases where the
100-
intended meaning isn't clear, using the full terms avoids ambiguity.
93+
Informally used to mean either an :term:`asynchronous generator
94+
function` or an :term:`asynchronous generator iterator`, depending on
95+
context. The formal terms :term:`asynchronous generator function` and
96+
:term:`asynchronous generator iterator` are uncommon in practice;
97+
"asynchronous generator" alone is almost always sufficient.
98+
99+
asynchronous generator function
100+
A function which returns an :term:`asynchronous generator iterator`.
101+
It looks like a coroutine function defined with :keyword:`async def`
102+
except that it contains :keyword:`yield` expressions for producing a
103+
series of values usable in an :keyword:`async for` loop. See :pep:`525`.
101104

102105
An asynchronous generator function may contain :keyword:`await`
103106
expressions as well as :keyword:`async for`, and :keyword:`async with`
104107
statements.
105108

106109
asynchronous generator iterator
107-
An object created by an :term:`asynchronous generator` function.
110+
An object created by an :term:`asynchronous generator function`.
108111

109112
This is an :term:`asynchronous iterator` which when called using the
110113
:meth:`~object.__anext__` method returns an awaitable object which will execute
@@ -594,23 +597,33 @@ Glossary
594597
.. index:: single: generator
595598

596599
generator
597-
A function which returns a :term:`generator iterator`. It looks like a
598-
normal function except that it contains :keyword:`yield` expressions
599-
for producing a series of values usable in a for-loop or that can be
600-
retrieved one at a time with the :func:`next` function.
600+
Informally used to mean either a :term:`generator function` or a
601+
:term:`generator iterator`, depending on context. The formal terms
602+
:term:`generator function` and :term:`generator iterator` are uncommon
603+
in practice; "generator" alone is almost always sufficient.
601604

602-
Usually refers to a generator function, but may refer to a
603-
*generator iterator* in some contexts. In cases where the intended
604-
meaning isn't clear, using the full terms avoids ambiguity.
605+
.. index:: single: generator function
606+
607+
generator function
608+
A function which returns a :term:`generator` object. It looks like a
609+
normal function except that it contains :keyword:`yield` expressions
610+
for producing a series of values usable in a :keyword:`for`\-loop or
611+
that can be retrieved one at a time with the :func:`next` function.
612+
See :ref:`yieldexpr`.
605613

606614
generator iterator
607-
An object created by a :term:`generator` function.
615+
An object created by a :term:`generator function` or a
616+
:term:`generator expression`.
608617

609618
Each :keyword:`yield` temporarily suspends processing, remembering the
610-
execution state (including local variables and pending
611-
try-statements). When the *generator iterator* resumes, it picks up where
612-
it left off (in contrast to functions which start fresh on every
613-
invocation).
619+
execution state (including local variables and pending try-statements).
620+
When the *generator iterator* resumes, it picks up where it left off
621+
(in contrast to functions which start fresh on every invocation).
622+
623+
Generator iterators also implement the :meth:`~generator.send` method
624+
to send a value into the suspended generator, and the
625+
:meth:`~generator.throw` method to raise an exception at the point
626+
where the generator was paused. See :ref:`generator-methods`.
614627

615628
.. index:: single: generator expression
616629

0 commit comments

Comments
 (0)