8000 bpo-45250: fix docs regarding `__iter__` and iterators being inconsistently required by CPython by brettcannon · Pull Request #29170 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45250: fix docs regarding __iter__ and iterators being inconsistently required by CPython #29170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 20, 2021
Merged
Prev Previous commit
Next Next commit
Add some glossary links to the data model
  • Loading branch information
brettcannon committed Oct 22, 2021
commit 2b11e3f8dbaaac67a75e835b3699eca0b744f828
28 changes: 15 additions & 13 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,13 @@ Callable types

A function or method which uses the :keyword:`yield` statement (see section
:ref:`yield`) is called a :dfn:`generator function`. Such a function, when
called, always returns an iterator object which can be used to execute the
body of the function: calling the iterator's :meth:`iterator.__next__`
method will cause the function to execute until it provides a value
using the :keyword:`!yield` statement. When the function executes a
:keyword:`return` statement or falls off the end, a :exc:`StopIteration`
exception is raised and the iterator will have reached the end of the set of
values to be returned.
called, always returns an :term:`iterator` object which can be used to
execute the body of the function: calling the iterator's
:meth:`iterator.__next__` method will cause the function to execute until
it provides a value using the :keyword:`!yield` statement. When the
function executes a :keyword:`return` statement or falls off the end, a
:exc:`StopIteration` exception is raised and the iterator will have
reached the end of the set of values to be returned.

Coroutine functions
.. index::
Expand All @@ -674,7 +674,7 @@ Callable types
A function or method which is defined using :keyword:`async def` and
which uses the :keyword:`yield` statement is called a
:dfn:`asynchronous generator function`. Such a function, when called,
returns an asynchronous iterator object which can be used in an
returns an :term:`asynchronous iterator` object which can be used in an
:keyword:`async for` statement to execute the body of the function.

Calling the asynchronous iterator's :meth:`aiterator.__anext__` method
Expand Down Expand Up @@ -2371,12 +2371,14 @@ through the object's keys; for sequences, it should iterate through the values.

.. method:: object.__iter__(self)

This method is called when an iterator is required for a container. This method
should return a new iterator object that can iterate over all the objects in the
container. For mappings, it should iterate over the keys of the container.
This method is called when an :term:`iterator` is required for a container.
This method should return a new iterator object that can iterate over all the
objects in the container. For mappings, it should iterate over the keys of
the container.

Iterator objects also need to implement this method; they are required to return
themselves. For more information on iterator objects, see :ref:`typeiter`.
Iterator objects also need to implement this method; they are required to
return themselves. For more information on iterator objects, see
:ref:`typeiter`.


.. method:: object.__reversed__(self)
Expand Down
0