Skip to content

Commit 1c487de

Browse files
encukoublaisepStanFromIreland
authored
[3.15] gh-141984: Add "exhausted" to glossary, link existing mentions (GH-157225) (#157271)
Co-authored-by: Blaise Pabon <blaise@gmail.com> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 98032d7 commit 1c487de

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
@@ -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+
: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
@@ -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
@@ -690,7 +690,7 @@ added elements by appending to the right and popping to the left::
690690
A `round-robin scheduler
691691
<https://en.wikipedia.org/wiki/Round-robin_scheduling>`_ can be implemented with
692692
input iterators stored in a :class:`deque`. Values are yielded from the active
693-
iterator in position zero. If that iterator is exhausted, it can be removed
693+
iterator in position zero. If that iterator is :term:`exhausted`, it can be removed
694694
with :meth:`~deque.popleft`; otherwise, it can be cycled back to the end with
695695
the :meth:`~deque.rotate` method::
696696

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
@@ -89,7 +89,7 @@ are always available. They are listed here in alphabetical order.
8989
anext(async_iterator, default, /)
9090

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

9494
This is the async variant of the :func:`next` builtin, and behaves
9595
similarly.
@@ -1250,7 +1250,7 @@ are always available. They are listed here in alphabetical order.
12501250
yielding the results. If additional *iterables* arguments are passed,
12511251
*function* must take that many arguments and is applied to the items from all
12521252
iterables in parallel. With multiple iterables, the iterator stops when the
1253-
shortest iterable is exhausted. If *strict* is ``True`` and one of the
1253+
shortest iterable is :term:`exhausted`. If *strict* is ``True`` and one of the
12541254
iterables is exhausted before the others, a :exc:`ValueError` is raised. For
12551255
cases where the function inputs are already arranged into argument tuples,
12561256
see :func:`itertools.starmap`.
@@ -1332,7 +1332,7 @@ are always available. They are listed here in alphabetical order.
13321332

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

13371337

13381338
.. class:: object()
@@ -2247,7 +2247,7 @@ are always available. They are listed here in alphabetical order.
22472247
the code that prepared these iterables. Python offers three different
22482248
approaches to dealing with this issue:
22492249

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

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

22642264
Unlike the default behavior, it raises a :exc:`ValueError` if one iterable
2265-
is exhausted before the others:
2265+
is :term:`exhausted` before the others:
22662266

22672267
>>> for item in zip(range(3), ['fee', 'fi', 'fo', 'fum'], strict=True): # doctest: +SKIP
22682268
... 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
@@ -2952,7 +2952,7 @@ features:
29522952

29532953
Close the iterator and free acquired resources.
29542954

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

Doc/library/unittest.mock.rst

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

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

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

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

0 commit comments

Comments
 (0)