Skip to content

gh-137597: Clarify flattening and bugfix for itertools.tee #137599

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,17 @@ loops that truncate the stream.
allows nested :func:`tee` calls to share the same underlying data
chain and to have a single update step rather than a chain of calls.

.. note::

:func:`tee` automatically "flattens" existing tee objects,
sharing the same underlying buffer instead of nesting them, to avoid
performance degradation.

.. versionchanged:: 3.13
Fixed a bug where re-teeing a tee iterator did not always return independent iterators.
Previously, the first iterator in the result could be the same object as the
input, causing inconsistent behavior.

The flattening property makes tee iterators efficiently peekable:

.. testcode::
Expand Down
Loading