@@ -474,7 +474,7 @@ loops that truncate the stream.
474
474
If *start * is zero or ``None ``, iteration starts at zero. Otherwise,
475
475
elements from the iterable are skipped until *start * is reached.
476
476
477
- If *stop * is ``None ``, iteration continues until the iterator is
477
+ If *stop * is ``None ``, iteration continues until the iterable is
478
478
exhausted, if at all. Otherwise, it stops at the specified position.
479
479
480
480
If *step * is ``None ``, the step defaults to one. Elements are returned
@@ -503,6 +503,10 @@ loops that truncate the stream.
503
503
yield element
504
504
next_i += step
505
505
506
+ If the input is an iterator, then fully consuming the *islice *
507
+ advances the input iterator by ``max(start, stop) `` steps regardless
508
+ of the *step * value.
509
+
506
510
507
511
.. function :: pairwise(iterable)
508
512
@@ -601,6 +605,8 @@ loops that truncate the stream.
601
605
# product('ABCD', 'xy') → Ax Ay Bx By Cx Cy Dx Dy
602
606
# product(range(2), repeat=3) → 000 001 010 011 100 101 110 111
603
607
608
+ if repeat < 0:
609
+ raise ValueError('repeat argument cannot be negative')
604
610
pools = [tuple(pool) for pool in iterables] * repeat
605
611
606
612
result = [[]]
@@ -684,6 +690,8 @@ loops that truncate the stream.
684
690
Roughly equivalent to::
685
691
686
692
def tee(iterable, n=2):
693
+ if n < 0:
694
+ raise ValueError('n must be >= 0')
687
695
iterator = iter(iterable)
688
696
shared_link = [None, None]
689
697
return tuple(_tee(iterator, shared_link) for _ in range(n))
@@ -703,6 +711,12 @@ loops that truncate the stream.
703
711
used anywhere else; otherwise, the *iterable * could get advanced without
704
712
the tee objects being informed.
705
713
714
+ When the input *iterable * is already a tee iterator object, all
715
+ members of the return tuple are constructed as if they had been
716
+ produced by the upstream :func: `tee ` call. This "flattening step"
717
+ allows nested :func: `tee ` calls to share the same underlying data
718
+ chain and to have a single update step rather than a chain of calls.
719
+
706
720
``tee `` iterators are not threadsafe. A :exc: `RuntimeError ` may be
707
721
raised when simultaneously using iterators returned by the same :func: `tee `
708
722
call, even if the original *iterable * is threadsafe.
0 commit comments