This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Make sure documentation is accurate for what an (async) iterable and (async) iterator are
Type: Stage: resolved
Components: Documentation Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon, quicknir, srittau
Priority: normal Keywords: patch

Created on 2021-09-20 20:03 by brett.cannon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29170 merged brett.cannon, 2021-10-22 19:39
PR 29650 merged brett.cannon, 2021-11-20 00:59
Messages (9)
msg402276 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-09-20 20:03
There's some inaccuracies when it comes to iterable and iterators (async and not). See https://mail.python.org/archives/list/python-dev@python.org/thread/3W7TDX5KNVQVGT5CUHBK33M7VNTP25DZ/#3W7TDX5KNVQVGT5CUHBK33M7VNTP25DZ for background.

Should probably check:

1. The glossary.
2. Language reference.
3. Built-ins.

This applies to iter()/__iter__/iterable, next()/__next__/iterator, and their async equivalents.
msg402304 - (view) Author: Sebastian Rittau (srittau) * Date: 2021-09-21 09:52
One thing I would strongly suggest for consistent terminology: Make "iterator" mean an object that has both "__next()__" and "__iter()__". This is consistent with how an iterator has been described in the glossary for a long time, but also consistent with (abc.collections|typing).Iterator.

Either invent a different term for objects having "__next__()" (but not necessarily "__iter__()"), or use a description like "an iterator or any other object that has a __next__() method".
msg404816 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-10-22 19:41
> One thing I would strongly suggest for consistent terminology: Make "iterator" mean an object that has both "__next()__" and "__iter()__".

The point of this issue, though, is to not make that claim as it's inaccurate.
msg404817 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-10-22 19:42
I also need to leave a comment on https://github.com/python/typeshed/issues/6030 if/when this is fixed.
msg405330 - (view) Author: Nir Friedman (quicknir) Date: 2021-10-29 19:22
Wouldn't a nicer resolution for this be to change `iter` (which effectively defines what is "iterable"), so that if `iter` does not find the `__iter__` or sequence protocol, it then looks for the iterator protocol (`__next__`), and if it finds that, return the argument?

In that way, all iterators would automatically get the sane implementation of `__iter__` by default, and we could say that in the "runtime", all iterators are iterable, matching the types. And people wouldn't need to implement `__iter__` any more on their iterators i.e. the recommendation could simply be dropped).
msg405451 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-11-01 16:44
> Wouldn't a nicer resolution for this be to change `iter`

Unfortunately that isn't backwards-compatible. Some people may explicitly want their iterators to not be iterables to guarantee that people who want an iterator get a fresh/new one instead of reusing a live iterator.
msg405458 - (view) Author: Nir Friedman (quicknir) Date: 2021-11-01 18:00
Okay, fair enough.
msg406634 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-11-20 00:40
New changeset be36e0634060c7d5dee8e8876fb888bbb53d992a by Brett Cannon in branch 'main':
bpo-45250: fix docs regarding `__iter__` and iterators being inconsistently required by CPython (GH-29170)
https://github.com/python/cpython/commit/be36e0634060c7d5dee8e8876fb888bbb53d992a
msg406809 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-11-22 23:09
New changeset 99aad31b7ad493d4feea04064bcd6b04061477f9 by Brett Cannon in branch '3.10':
[3.10] bpo-45250: fix docs regarding `__iter__` and iterators being inconsistently required by CPython (GH-29170) (GH-29650)
https://github.com/python/cpython/commit/99aad31b7ad493d4feea04064bcd6b04061477f9
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89413
2021-11-22 23:09:30brett.cannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-11-22 23:09:23brett.cannonsetmessages: + msg406809
2021-11-20 00:59:53brett.cannonsetstage: patch review
pull_requests: + pull_request27888
2021-11-20 00:40:38brett.cannonsetmessages: + msg406634
2021-11-01 18:00:31quicknirsetmessages: + msg405458
2021-11-01 16:44:31brett.cannonsetmessages: + msg405451
2021-10-29 19:22:28quicknirsetnosy: + quicknir
messages: + msg405330
2021-10-22 19:42:19brett.cannonsetmessages: + msg404817
2021-10-22 19:41:28brett.cannonsetmessages: + msg404816
stage: patch review -> (no value)
2021-10-22 19:39:51brett.cannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request27443
2021-09-21 09:52:18srittausetnosy: + srittau
messages: + msg402304
2021-09-20 20:03:02brett.cannoncreate