summaryrefslogtreecommitdiffstats
path: root/Doc/c-api/iter.rst
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2021-11-20 00:40:34 (GMT)
committerGitHub <noreply@github.com>2021-11-20 00:40:34 (GMT)
commitbe36e0634060c7d5dee8e8876fb888bbb53d992a (patch)
treedcf28e3105e12b272cdca00de2b260dec6805183 /Doc/c-api/iter.rst
parent4c616911b69ce07fb35da1721506bfaba0998c30 (diff)
downloadcpython-be36e0634060c7d5dee8e8876fb888bbb53d992a.zip
cpython-be36e0634060c7d5dee8e8876fb888bbb53d992a.tar.gz
cpython-be36e0634060c7d5dee8e8876fb888bbb53d992a.tar.bz2
bpo-45250: fix docs regarding `__iter__` and iterators being inconsistently required by CPython (GH-29170)
It is now considered a historical accident that e.g. `for` loops and the `iter()` built-in function do not require the iterators they work with to define `__iter__`, only `__next__`.
Diffstat (limited to 'Doc/c-api/iter.rst')
-rw-r--r--Doc/c-api/iter.rst13
1 files changed, 7 insertions, 6 deletions
diff --git a/Doc/c-api/iter.rst b/Doc/c-api/iter.rst
index f7106f4..3e388bb 100644
--- a/Doc/c-api/iter.rst
+++ b/Doc/c-api/iter.rst
@@ -9,8 +9,8 @@ There are two functions specifically for working with iterators.
.. c:function:: int PyIter_Check(PyObject *o)
- Return non-zero if the object *o* supports the iterator protocol, and ``0``
- otherwise. This function always succeeds.
+ Return non-zero if the object *o* can be safely passed to
+ :c:func:`PyIter_Next`, and ``0`` otherwise. This function always succeeds.
.. c:function:: int PyAIter_Check(PyObject *o)
@@ -21,10 +21,11 @@ There are two functions specifically for working with iterators.
.. c:function:: PyObject* PyIter_Next(PyObject *o)
- Return the next value from the iteration *o*. The object must be an iterator
- (it is up to the caller to check this). If there are no remaining values,
- returns ``NULL`` with no exception set. If an error occurs while retrieving
- the item, returns ``NULL`` and passes along the exception.
+ Return the next value from the iterator *o*. The object must be an iterator
+ according to :c:func:`PyIter_Check` (it is up to the caller to check this).
+ If there are no remaining values, returns ``NULL`` with no exception set.
+ If an error occurs while retrieving the item, returns ``NULL`` and passes
+ along the exception.
To write a loop which iterates over an iterator, the C code should look
something like this::