Skip to content

Commit 6ce5cb0

Browse files
committed
Working fix
1 parent 17b3bc9 commit 6ce5cb0

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

Doc/library/itertools.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,6 @@ loops that truncate the stream.
707707
except StopIteration:
708708
return
709709

710-
Once a :func:`tee` has been created, the original *iterable* should not be
711-
used anywhere else; otherwise, the *iterable* could get advanced without
712-
the tee objects being informed.
713-
714710
When the input *iterable* is already a tee iterator object, all
715711
members of the return tuple are constructed as if they had been
716712
produced by the upstream :func:`tee` call. This "flattening step"

Lib/test/test_itertools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,10 +1249,11 @@ def test_tee(self):
12491249
self.assertEqual(len(result), n)
12501250
self.assertEqual([list(x) for x in result], [list('abc')]*n)
12511251

1252-
# tee pass-through to copyable iterator
1252+
# tee objects are independent (see bug gh-123884)
12531253
a, b = tee('abc')
12541254
c, d = tee(a)
1255-
self.assertTrue(a is c)
1255+
e, f = tee(c)
1256+
self.assertTrue(len({a, b, c, d, e, f}) == 6)
12561257

12571258
# test tee_new
12581259
t1, t2 = tee('abc')

Modules/itertoolsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n)
10581058
Py_DECREF(result);
10591059
return NULL;
10601060
}
1061-
if (copyfunc != NULL) {
1061+
if (copyfunc != NULL && 0) {
10621062
copyable = it;
10631063
}
10641064
else {

0 commit comments

Comments
 (0)