Skip to content

Conversation

@srittau
Copy link
Contributor

@srittau srittau commented Nov 15, 2023

prepend() works with arbitrary iterables, not only iterators. In fact, the example given uses a list, which is iterable, but not an iterator.

Spotted by @AlexWaygood in python/typeshed#10992.


📚 Documentation preview 📚: https://cpython-previews--112113.org.readthedocs.build/

`prepend()` works with arbitrary iterables, not only iterators. In fact,
the example given uses a `list`, which is iterable, but not an iterator.
@srittau srittau requested a review from rhettinger as a code owner November 15, 2023 12:10
@bedevere-app bedevere-app bot added awaiting review docs Documentation in the Doc dir skip news labels Nov 15, 2023
@srittau
Copy link
Contributor Author

srittau commented Nov 15, 2023

(Considering this is a trivial fix, I don't think this needs an issue, but I can open one if requested.)

@hugovk hugovk added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Nov 19, 2023
@rhettinger
Copy link
Contributor

While it is true that any iterable will suffice, the intent and principal use case is for prepending a value to an iterator stream. Switching the variable name to iterable hides the intended use case and is also a bit misleading because it suggests that the iterable is altered rather than the iterator stream.

So, I'm going to leave this as-is. The code is not wrong and the choice of parameter name can be anything that is useful. For someone writing type annotations, they can and should use Iterable.

@rhettinger
Copy link
Contributor

After more thought, I think this edit is fine.

@hugovk hugovk merged commit 6c47eac into python:main Nov 22, 2023
@miss-islington-app
Copy link

Thanks @srittau for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 22, 2023
`prepend()` works with arbitrary iterables, not only iterators. In fact,
the example given uses a `list`, which is iterable, but not an iterator.
(cherry picked from commit 6c47eac)

Co-authored-by: Sebastian Rittau <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Nov 22, 2023

GH-112310 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Nov 22, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 22, 2023
`prepend()` works with arbitrary iterables, not only iterators. In fact,
the example given uses a `list`, which is iterable, but not an iterator.
(cherry picked from commit 6c47eac)

Co-authored-by: Sebastian Rittau <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Nov 22, 2023

GH-112311 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Nov 22, 2023
hugovk pushed a commit that referenced this pull request Nov 22, 2023
…12311)

Fix docstring and var name of itertools recipe (GH-112113)

`prepend()` works with arbitrary iterables, not only iterators. In fact,
the example given uses a `list`, which is iterable, but not an iterator.
(cherry picked from commit 6c47eac)

Co-authored-by: Sebastian Rittau <[email protected]>
hugovk pushed a commit that referenced this pull request Nov 22, 2023
…12310)

Fix docstring and var name of itertools recipe (GH-112113)

`prepend()` works with arbitrary iterables, not only iterators. In fact,
the example given uses a `list`, which is iterable, but not an iterator.
(cherry picked from commit 6c47eac)

Co-authored-by: Sebastian Rittau <[email protected]>
@srittau srittau deleted the itertools-recipe branch November 22, 2023 07:23
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
`prepend()` works with arbitrary iterables, not only iterators. In fact,
the example given uses a `list`, which is iterable, but not an iterator.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
`prepend()` works with arbitrary iterables, not only iterators. In fact,
the example given uses a `list`, which is iterable, but not an iterator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip issue skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants