Skip to content

Commit 01c089c

Browse files
encukoublaisep
andcommitted
gh-141984: Add "exhausted" to glossary, link existing mentions
Co-authored-by: Blaise Pabon <blaise@gmail.com>
1 parent 52ffffe commit 01c089c

12 files changed

Lines changed: 44 additions & 34 deletions

File tree

Doc/c-api/typeobj.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,9 +1869,10 @@ and :c:data:`PyType_Type` effectively act as defaults.)
18691869

18701870
PyObject *tp_iternext(PyObject *self);
18711871

1872-
When the iterator is exhausted, it must return ``NULL``; a :exc:`StopIteration`
1873-
exception may or may not be set. When another error occurs, it must return
1874-
``NULL`` too. Its presence signals that the instances of this type are
1872+
When the iterator is :term:`exhausted`, the ``tp_iternext`` function must
1873+
return ``NULL``; a :exc:`StopIteration` exception may or may not be set.
1874+
When another error occurs, it must return ``NULL`` too.
1875+
The presence of ``tp_iternext`` signals that the instances of this type are
18751876
iterators.
18761877

18771878
Iterator types should also define the :c:member:`~PyTypeObject.tp_iter` function, and that

Doc/glossary.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,14 @@ Glossary
505505
of an object, such as the value of type aliases created with the :keyword:`type`
506506
statement.
507507

508+
exhausted
509+
An :term:`iterator` that has produced all of its values is said to be
510+
:dfn:`exhausted`.
511+
Further attempts to get the next value (for example, calls to
512+
:py:func:`next`) raise :py:exc:`StopIteration`
513+
(or :py:exc:`StopAsyncIteration` in the case of an :term:`asynchronous
514+
iterator`).
515+
508516
expression
509517
A piece of syntax which can be evaluated to some value. In other words,
510518
an expression is an accumulation of expression elements like literals,
@@ -869,7 +877,7 @@ Glossary
869877
:meth:`~iterator.__next__` method (or passing it to the built-in function
870878
:func:`next`) return successive items in the stream. When no more data
871879
are available a :exc:`StopIteration` exception is raised instead. At this
872-
point, the iterator object is exhausted and any further calls to its
880+
point, the iterator object is :term:`exhausted` and any further calls to its
873881
:meth:`!__next__` method just raise :exc:`StopIteration` again. Iterators
874882
are required to have an :meth:`~iterator.__iter__` method that returns the iterator
875883
object itself so every iterator is also iterable and may be used in most

Doc/howto/functional.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,10 @@ returns them in a tuple::
720720
zip(['a', 'b', 'c'], (1, 2, 3)) =>
721721
('a', 1), ('b', 2), ('c', 3)
722722

723-
It doesn't construct an in-memory list and exhaust all the input iterators
724-
before returning; instead tuples are constructed and returned only if they're
725-
requested. (The technical term for this behaviour is `lazy evaluation
723+
It doesn't construct an in-memory list and :term:`exhaust <exhausted>` all
724+
the input iterators before returning; instead tuples are constructed and
725+
returned only if they're requested.
726+
(The technical term for this behaviour is `lazy evaluation
726727
<https://en.wikipedia.org/wiki/Lazy_evaluation>`__.)
727728

728729
This iterator is intended to be used with iterables that are all of the same
@@ -783,7 +784,7 @@ element *n* times, or returns the element endlessly if *n* is not provided. ::
783784
:func:`itertools.chain(iterA, iterB, ...) <itertools.chain>` takes an arbitrary
784785
number of iterables as input, and returns all the elements of the first
785786
iterator, then all the elements of the second, and so on, until all of the
786-
iterables have been exhausted. ::
787+
iterables have been :term:`exhausted`. ::
787788

788789
itertools.chain(['a', 'b', 'c'], (1, 2, 3)) =>
789790
a, b, c, 1, 2, 3
@@ -878,7 +879,7 @@ iterable's results. ::
878879

879880
:func:`itertools.compress(data, selectors) <itertools.compress>` takes two
880881
iterators and returns only those elements of *data* for which the corresponding
881-
element of *selectors* is true, stopping whenever either one is exhausted::
882+
element of *selectors* is true, stopping whenever either one is :term:`exhausted`::
882883

883884
itertools.compress([1, 2, 3, 4, 5], [True, True, False, False, True]) =>
884885
1, 2, 5
@@ -1028,7 +1029,7 @@ that takes two elements and returns a single value. :func:`functools.reduce`
10281029
takes the first two elements A and B returned by the iterator and calculates
10291030
``func(A, B)``. It then requests the third element, C, calculates
10301031
``func(func(A, B), C)``, combines this result with the fourth element returned,
1031-
and continues until the iterable is exhausted. If the iterable returns no
1032+
and continues until the iterable is :term:`exhausted`. If the iterable returns no
10321033
values at all, a :exc:`TypeError` exception is raised. If the initial value is
10331034
supplied, it's used as a starting point and ``func(initial_value, A)`` is the
10341035
first calculation. ::

Doc/library/collections.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ added elements by appending to the right and popping to the left::
699699
A `round-robin scheduler
700700
<https://en.wikipedia.org/wiki/Round-robin_scheduling>`_ can be implemented with
701701
input iterators stored in a :class:`deque`. Values are yielded from the active
702-
iterator in position zero. If that iterator is exhausted, it can be removed
702+
iterator in position zero. If that iterator is :term:`exhausted`, it can be removed
703703
with :meth:`~deque.popleft`; otherwise, it can be cycled back to the end with
704704
the :meth:`~deque.rotate` method::
705705

Doc/library/dis.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ iterations of the loop.
14271427

14281428
``STACK[-1]`` is an :term:`iterator`. Call its :meth:`~iterator.__next__` method.
14291429
If this yields a new value, push it on the stack (leaving the iterator below
1430-
it). If the iterator indicates it is exhausted then the byte code counter is
1430+
it). If the iterator indicates it is :term:`exhausted` then the byte code counter is
14311431
incremented by *delta*.
14321432

14331433
.. versionchanged:: 3.12

Doc/library/functions.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ are always available. They are listed here in alphabetical order.
129129
anext(async_iterator, default, /)
130130

131131
When awaited, return the next item from the given :term:`asynchronous
132-
iterator`, or *default* if given and the iterator is exhausted.
132+
iterator`, or *default* if given and the iterator is :term:`exhausted`.
133133

134134
This is the async variant of the :func:`next` builtin, and behaves
135135
similarly.
@@ -1223,7 +1223,7 @@ are always available. They are listed here in alphabetical order.
12231223
process_block(block)
12241224

12251225
*stop_exception* is useful for callables
1226-
which report exhaustion by raising an exception
1226+
which report :term:`exhaustion <exhausted>` by raising an exception
12271227
instead of returning a special value.
12281228
For example, draining a queue::
12291229

@@ -1315,7 +1315,7 @@ are always available. They are listed here in alphabetical order.
13151315
yielding the results. If additional *iterables* arguments are passed,
13161316
*function* must take that many arguments and is applied to the items from all
13171317
iterables in parallel. With multiple iterables, the iterator stops when the
1318-
shortest iterable is exhausted. If *strict* is ``True`` and one of the
1318+
shortest iterable is :term:`exhausted`. If *strict* is ``True`` and one of the
13191319
iterables is exhausted before the others, a :exc:`ValueError` is raised. For
13201320
cases where the function inputs are already arranged into argument tuples,
13211321
see :func:`itertools.starmap`.
@@ -1397,7 +1397,7 @@ are always available. They are listed here in alphabetical order.
13971397

13981398
Retrieve the next item from the :term:`iterator` by calling its
13991399
:meth:`~iterator.__next__` method. If *default* is given, it is returned
1400-
if the iterator is exhausted, otherwise :exc:`StopIteration` is raised.
1400+
if the iterator is :term:`exhausted`, otherwise :exc:`StopIteration` is raised.
14011401

14021402

14031403
.. class:: object()
@@ -2312,7 +2312,7 @@ are always available. They are listed here in alphabetical order.
23122312
the code that prepared these iterables. Python offers three different
23132313
approaches to dealing with this issue:
23142314

2315-
* By default, :func:`zip` stops when the shortest iterable is exhausted.
2315+
* By default, :func:`zip` stops when the shortest iterable is :term:`exhausted`.
23162316
It will ignore the remaining items in the longer iterables, cutting off
23172317
the result to the length of the shortest iterable::
23182318

@@ -2327,7 +2327,7 @@ are always available. They are listed here in alphabetical order.
23272327
[('a', 1), ('b', 2), ('c', 3)]
23282328

23292329
Unlike the default behavior, it raises a :exc:`ValueError` if one iterable
2330-
is exhausted before the others:
2330+
is :term:`exhausted` before the others:
23312331

23322332
>>> for item in zip(range(3), ['fee', 'fi', 'fo', 'fum'], strict=True): # doctest: +SKIP
23332333
... print(item)

Doc/library/http.client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ HTTPConnection Objects
277277
instance of :class:`io.TextIOBase`, the data returned by the ``read()``
278278
method will be encoded as ISO-8859-1, otherwise the data returned by
279279
``read()`` is sent as is. If *body* is an iterable, the elements of the
280-
iterable are sent as is until the iterable is exhausted.
280+
iterable are sent as is until the iterable is :term:`exhausted`.
281281

282282
The *headers* argument should be a mapping of extra HTTP headers to send
283283
with the request. A :rfc:`Host header <2616#section-14.23>`

Doc/library/itertools.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ loops that truncate the stream.
158158
Loops over the input iterable and accumulates data into tuples up to
159159
size *n*. The input is consumed lazily, just enough to fill a batch.
160160
The result is yielded as soon as the batch is full or when the input
161-
iterable is exhausted:
161+
iterable is :term:`exhausted`:
162162

163163
.. doctest::
164164

@@ -188,7 +188,7 @@ loops that truncate the stream.
188188
.. function:: chain(*iterables)
189189

190190
Make an iterator that returns elements from the first iterable until
191-
it is exhausted, then proceeds to the next iterable, until all of the
191+
it is :term:`exhausted`, then proceeds to the next iterable, until all of the
192192
iterables are exhausted. This combines multiple data sources into a
193193
single iterator. Roughly equivalent to::
194194

@@ -305,7 +305,7 @@ loops that truncate the stream.
305305

306306
Make an iterator that returns elements from *data* where the
307307
corresponding element in *selectors* is true. Stops when either the
308-
*data* or *selectors* iterables have been exhausted. Roughly
308+
*data* or *selectors* iterables have been :term:`exhausted`. Roughly
309309
equivalent to::
310310

311311
def compress(data, selectors):
@@ -341,7 +341,7 @@ loops that truncate the stream.
341341
.. function:: cycle(iterable)
342342

343343
Make an iterator returning elements from the *iterable* and saving a
344-
copy of each. When the iterable is exhausted, return elements from
344+
copy of each. When the iterable is :term:`exhausted`, return elements from
345345
the saved copy. Repeats indefinitely. Roughly equivalent to::
346346

347347
def cycle(iterable):
@@ -472,7 +472,7 @@ loops that truncate the stream.
472472
elements from the iterable are skipped until *start* is reached.
473473

474474
If *stop* is ``None``, iteration continues until the input is
475-
exhausted, if at all. Otherwise, it stops at the specified position.
475+
:term:`exhausted`, if at all. Otherwise, it stops at the specified position.
476476

477477
If *step* is ``None``, the step defaults to one. Elements are returned
478478
consecutively unless *step* is set higher than one which results in
@@ -677,9 +677,9 @@ loops that truncate the stream.
677677
Note, the element that first fails the predicate condition is
678678
consumed from the input iterator and there is no way to access it.
679679
This could be an issue if an application wants to further consume the
680-
input iterator after *takewhile* has been run to exhaustion. To work
681-
around this problem, consider using `more-itertools before_and_after()
682-
<https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.before_and_after>`_
680+
input iterator after *takewhile* has been run to :term:`exhaustion <exhausted>`.
681+
To work around this problem, consider using `more-itertools before_and_after()
682+
<https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.before_and_after>`__
683683
instead.
684684

685685

@@ -766,7 +766,7 @@ loops that truncate the stream.
766766
If the iterables are of uneven length, missing values are filled-in
767767
with *fillvalue*. If not specified, *fillvalue* defaults to ``None``.
768768

769-
Iteration continues until the longest iterable is exhausted.
769+
Iteration continues until the longest iterable is :term:`exhausted`.
770770

771771
Roughly equivalent to::
772772

Doc/library/os.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3002,7 +3002,7 @@ features:
30023002

30033003
Close the iterator and free acquired resources.
30043004

3005-
This is called automatically when the iterator is exhausted or garbage
3005+
This is called automatically when the iterator is :term:`exhausted` or garbage
30063006
collected, or when an error happens during iterating. However it
30073007
is advisable to call it explicitly or use the :keyword:`with`
30083008
statement.

Doc/library/unittest.mock.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ object::
922922
exception,
923923
- if ``side_effect`` is an iterable, the async function will return the
924924
next value of the iterable, however, if the sequence of result is
925-
exhausted, ``StopAsyncIteration`` is raised immediately,
925+
:term:`exhausted`, ``StopAsyncIteration`` is raised immediately,
926926
- if ``side_effect`` is not defined, the async function will return the
927927
value defined by ``return_value``, hence, by default, the async function
928928
returns a new :class:`AsyncMock` object.
@@ -1272,7 +1272,7 @@ To remove a :attr:`~Mock.side_effect`, and return to the default behaviour, set
12721272
6
12731273

12741274
The :attr:`~Mock.side_effect` can also be any iterable object. Repeated calls to the mock
1275-
will return values from the iterable (until the iterable is exhausted and
1275+
will return values from the iterable (until the iterable is :term:`exhausted` and
12761276
a :exc:`StopIteration` is raised):
12771277

12781278
>>> m = MagicMock(side_effect=[1, 2, 3])
@@ -2949,7 +2949,7 @@ precedence remains the same:
29492949
>>> order_mock.get_value()
29502950
'third'
29512951

2952-
If :attr:`~Mock.side_effect` is exhausted, the order of precedence will not
2952+
If :attr:`~Mock.side_effect` is :term:`exhausted`, the order of precedence will not
29532953
cause a value to be obtained from the successors. Instead, ``StopIteration``
29542954
exception is raised.
29552955

0 commit comments

Comments
 (0)