Skip to content

gh-155856: Rephrase doc for "iter" to avoid "collection" - #155857

Open
wjandrea wants to merge 1 commit into
python:mainfrom
wjandrea:patch-4
Open

gh-155856: Rephrase doc for "iter" to avoid "collection"#155857
wjandrea wants to merge 1 commit into
python:mainfrom
wjandrea:patch-4

Conversation

@wjandrea

@wjandrea wjandrea commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #155856 - The term "collection" is misleading.
Also add link to "sequence".

Comment thread Doc/library/functions.rst Outdated
@wjandrea
wjandrea marked this pull request as draft August 15, 2026 16:16
@read-the-docs-community

read-the-docs-community Bot commented Aug 15, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34082506 | 📁 Comparing 41f1d56 against main (948fd7e)

  🔍 Preview build  

1 file changed
± library/functions.html

Fixes python#155856 - The term "collection" is misleading.
Also add link to "sequence".
@wjandrea
wjandrea marked this pull request as ready for review August 15, 2026 17:08
picnixz
picnixz previously approved these changes Aug 15, 2026

@picnixz picnixz left a comment

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.

Ah I overlooked the "term" around the sequence. Ok.

Comment thread Doc/library/functions.rst
the sequence protocol (the :meth:`~object.__getitem__` method with integer arguments
second argument, the single argument must be an object that supports the
:term:`iterable` protocol (the :meth:`~object.__iter__` method) or the
:term:`sequence` protocol (the :meth:`~object.__getitem__` method with integer arguments

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.

Linking to the sequence glossary entry isn't quite correct here, it has stricter requirements (i.e., a __len__ method) than iter()'s requirements.

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.

Oh we have a discrepancy between Sequence protocol in collections.abc and the one in C then: https://docs.python.org/3/c-api/sequence.html#c.PySequence_Check

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.

Also, we say:

The sequence iteration protocol (used, for example, in for loops), expects that an IndexError will be raised for illegal indexes to allow proper detection of the end of a sequence.

So I'km not sure you need __len__

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.

Actually, I think it's the C page which should mentions the __len__ as well.

@picnixz
picnixz dismissed their stale review August 15, 2026 20:16

A link to the sequence protocol was actually incorrect.

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

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

iter() doesn't require a "collection"

3 participants