Skip to content

Commit 04ed190

Browse files
StanFromIrelandencukoublaisep
authored
[3.14] gh-141984: Add "exhausted" to glossary, link existing mentions (GH-157225) (GH-157272)
(cherry picked from commit 9bd670c) Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Blaise Pabon <blaise@gmail.com>
1 parent a6d25db commit 04ed190

12 files changed

Lines changed: 43 additions & 33 deletions

File tree

Doc/c-api/typeobj.rst

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

19291929
PyObject *tp_iternext(PyObject *self);
19301930

1931-
When the iterator is exhausted, it must return ``NULL``; a :exc:`StopIteration`
1932-
exception may or may not be set. When another error occurs, it must return
1933-
``NULL`` too. Its presence signals that the instances of this type are
1931+
When the iterator is :term:`exhausted`, the ``tp_iternext`` function must
1932+
return ``NULL``; a :exc:`StopIteration` exception may or may not be set.
1933+
When another error occurs, it must return ``NULL`` too.
1934+
The presence of ``tp_iternext`` signals that the instances of this type are
19341935
iterators.
19351936

19361937
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+
:func:`next`) raise :exc:`StopIteration`
513+
(or :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
@@ -723,9 +723,10 @@ returns them in a tuple::
723723
zip(['a', 'b', 'c'], (1, 2, 3)) =>
724724
('a', 1), ('b', 2), ('c', 3)
725725

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

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

791792
itertools.chain(['a', 'b', 'c'], (1, 2, 3)) =>
792793
a, b, c, 1, 2, 3
@@ -881,7 +882,7 @@ iterable's results. ::
881882

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

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

Doc/library/collections.rst

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

Doc/library/dis.rst

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

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

14301430
.. versionchanged:: 3.12

Doc/library/functions.rst

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

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

9292
This is the async variant of the :func:`next` builtin, and behaves
9393
similarly.
@@ -1216,7 +1216,7 @@ are always available. They are listed here in alphabetical order.
12161216
yielding the results. If additional *iterables* arguments are passed,
12171217
*function* must take that many arguments and is applied to the items from all
12181218
iterables in parallel. With multiple iterables, the iterator stops when the
1219-
shortest iterable is exhausted. If *strict* is ``True`` and one of the
1219+
shortest iterable is :term:`exhausted`. If *strict* is ``True`` and one of the
12201220
iterables is exhausted before the others, a :exc:`ValueError` is raised. For
12211221
cases where the function inputs are already arranged into argument tuples,
12221222
see :func:`itertools.starmap`.
@@ -1298,7 +1298,7 @@ are always available. They are listed here in alphabetical order.
12981298

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

13031303

13041304
.. class:: object()
@@ -2174,7 +2174,7 @@ are always available. They are listed here in alphabetical order.
21742174
the code that prepared these iterables. Python offers three different
21752175
approaches to dealing with this issue:
21762176

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

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

21912191
Unlike the default behavior, it raises a :exc:`ValueError` if one iterable
2192-
is exhausted before the others:
2192+
is :term:`exhausted` before the others:
21932193

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

Doc/library/http.client.rst

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

274274
The *headers* argument should be a mapping of extra HTTP headers to send
275275
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
@@ -161,7 +161,7 @@ loops that truncate the stream.
161161
Loops over the input iterable and accumulates data into tuples up to
162162
size *n*. The input is consumed lazily, just enough to fill a batch.
163163
The result is yielded as soon as the batch is full or when the input
164-
iterable is exhausted:
164+
iterable is :term:`exhausted`:
165165

166166
.. doctest::
167167

@@ -191,7 +191,7 @@ loops that truncate the stream.
191191
.. function:: chain(*iterables)
192192

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

@@ -300,7 +300,7 @@ loops that truncate the stream.
300300

301301
Make an iterator that returns elements from *data* where the
302302
corresponding element in *selectors* is true. Stops when either the
303-
*data* or *selectors* iterables have been exhausted. Roughly
303+
*data* or *selectors* iterables have been :term:`exhausted`. Roughly
304304
equivalent to::
305305

306306
def compress(data, selectors):
@@ -336,7 +336,7 @@ loops that truncate the stream.
336336
.. function:: cycle(iterable)
337337

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

342342
def cycle(iterable):
@@ -467,7 +467,7 @@ loops that truncate the stream.
467467
elements from the iterable are skipped until *start* is reached.
468468

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

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

680680

@@ -761,7 +761,7 @@ loops that truncate the stream.
761761
If the iterables are of uneven length, missing values are filled-in
762762
with *fillvalue*. If not specified, *fillvalue* defaults to ``None``.
763763

764-
Iteration continues until the longest iterable is exhausted.
764+
Iteration continues until the longest iterable is :term:`exhausted`.
765765

766766
Roughly equivalent to::
767767

Doc/library/os.rst

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

29002900
Close the iterator and free acquired resources.
29012901

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

Doc/library/unittest.mock.rst

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

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

12751275
>>> m = MagicMock(side_effect=[1, 2, 3])
@@ -2946,7 +2946,7 @@ precedence remains the same:
29462946
>>> order_mock.get_value()
29472947
'third'
29482948

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

0 commit comments

Comments
 (0)