File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -730,6 +730,29 @@ loops that truncate the stream.
730730 produced by the upstream :func: `tee ` call. This "flattening step"
731731 allows nested :func: `tee ` calls to share the same underlying data
732732 chain and to have a single update step rather than a chain of calls.
733+
734+ .. note ::
735+
736+ :func: `tee ` automatically "flattens" existing tee objects,
737+ sharing the same underlying buffer instead of nesting them, to avoid
738+ performance degradation. This flattening behavior has existed since Python 3.7.
739+
740+ .. versionchanged :: 3.13
741+ Fixed a bug where re-teeing the first iterator did not correctly flatten
742+ the iterator chain in all cases. Previously, this could lead to unnecessary
743+ nesting and performance degradation in rare scenarios.
744+
745+ .. doctest ::
746+
747+ >>> it = iter ([1 , 2 , 3 ])
748+ >>> a, b = tee(it)
749+ >>> c, d = tee(a)
750+ >>> list (b)
751+ [1, 2, 3]
752+ >>> list (c)
753+ [1, 2, 3]
754+ >>> list (d)
755+ [1, 2, 3]
733756
734757 The flattening property makes tee iterators efficiently peekable:
735758
You can’t perform that action at this time.
0 commit comments