Skip to content

gh-141984: Move generator iterator reference out of syntax docs - #154884

Open
encukou wants to merge 6 commits into
python:mainfrom
encukou:move-generator-iterator-out
Open

gh-141984: Move generator iterator reference out of syntax docs#154884
encukou wants to merge 6 commits into
python:mainfrom
encukou:move-generator-iterator-out

Conversation

@encukou

@encukou encukou commented Jul 29, 2026

Copy link
Copy Markdown
Member

The Expressions section of the docs contains reference documentation (that is, descriptions of all the methods) for Generator-iterators and Asynchronous generator-iterators.
These look out of place here, and interfere with explaining the syntax around yield.

There are two places that would make a better home for these: stdtypes in Library and datamodel in Reference. (These two have a lot of overlap, for what I think are mostly historical reasons, but fixing that is out of scope for this PR.)
I think stdtypes is the better place to put these.

I added an introduction to Generators here, which currently overlaps a bit with the Yield expressions in the grammar docs. I'll be reworking Yield expressions next.

@read-the-docs-community

read-the-docs-community Bot commented Jul 29, 2026

Copy link
Copy Markdown

Comment thread Doc/library/stdtypes.rst
methods.
More information about generators can be found in :ref:`the documentation for
the yield expression <yieldexpr>`.
Python's :term:`generators <generator>` -- or more precisely,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unfortunately isn't helping #126052.

Comment thread Doc/library/stdtypes.rst
For example::

>>> class CardDeck:
... def __iter__(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation.

Comment thread Doc/library/stdtypes.rst
... yield 'ace of hearts'

>>> list(CardDeck())
... ['three of clubs', 'ace of hearts']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
... ['three of clubs', 'ace of hearts']
['three of clubs', 'ace of hearts']

Comment thread Doc/library/stdtypes.rst
.. index:: pair: object; asynchronous-generator
.. _asynchronous-generator-methods:

Asynchronous generator-iterators

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Asynchronous generator-iterators
Asynchronous generator iterators

Comment thread Doc/library/stdtypes.rst
Asynchronous generator-iterators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This subsection describes the methods of an asynchronous generator iterator,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An expanded introduction would be nice here, too. Although that can be done in a follow up.

Comment thread Doc/library/stdtypes.rst
awaitable instead raises a :exc:`StopAsyncIteration` exception,
signalling that the asynchronous iteration has completed.

This method is normally called implicitly by a :keyword:`async for` loop,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This method is normally called implicitly by a :keyword:`async for` loop,
This method is normally called implicitly by an :keyword:`async for` loop,

Comment thread Doc/library/stdtypes.rst
returns the next yielded value as the value of the raised
:exc:`StopIteration`, or raises :exc:`StopAsyncIteration`.

:meth:`asend` is called to start the asynchronous

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:meth:`asend` is called to start the asynchronous
When :meth:`asend` is called to start the asynchronous

lost during the refactor.

Comment thread Doc/library/stdtypes.rst
For backwards compatibility, however, the second signature is
supported.
An exception instance is created from three arguments in the same way as in
:meth:`generator.throw`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:meth:`generator.throw`
:meth:`generator.throw`.

Comment thread Doc/tools/removed-ids.txt
using/windows.html: virtual-environments
using/windows.html: windows-full

# Moved to library/stdtypes:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These unfortunately do seem like things people would link to (in fact, they do), it would be nice to preserve these (possibly via #151113).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants