@@ -474,7 +474,7 @@ loops that truncate the stream.
474474 If *start * is zero or ``None ``, iteration starts at zero. Otherwise,
475475 elements from the iterable are skipped until *start * is reached.
476476
477- If *stop * is ``None ``, iteration continues until the iterator is
477+ If *stop * is ``None ``, iteration continues until the iterable is
478478 exhausted, if at all. Otherwise, it stops at the specified position.
479479
480480 If *step * is ``None ``, the step defaults to one. Elements are returned
@@ -503,6 +503,10 @@ loops that truncate the stream.
503503 yield element
504504 next_i += step
505505
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+
506510
507511.. function :: pairwise(iterable)
508512
@@ -601,6 +605,8 @@ loops that truncate the stream.
601605 # product('ABCD', 'xy') → Ax Ay Bx By Cx Cy Dx Dy
602606 # product(range(2), repeat=3) → 000 001 010 011 100 101 110 111
603607
608+ if repeat < 0:
609+ raise ValueError('repeat argument cannot be negative')
604610 pools = [tuple(pool) for pool in iterables] * repeat
605611
606612 result = [[]]
@@ -684,6 +690,8 @@ loops that truncate the stream.
684690 Roughly equivalent to::
685691
686692 def tee(iterable, n=2):
693+ if n < 0:
694+ raise ValueError('n must be >= 0')
687695 iterator = iter(iterable)
688696 shared_link = [None, None]
689697 return tuple(_tee(iterator, shared_link) for _ in range(n))
@@ -703,6 +711,12 @@ loops that truncate the stream.
703711 used anywhere else; otherwise, the *iterable * could get advanced without
704712 the tee objects being informed.
705713
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+
706720 ``tee `` iterators are not threadsafe. A :exc: `RuntimeError ` may be
707721 raised when simultaneously using iterators returned by the same :func: `tee `
708722 call, even if the original *iterable * is threadsafe.
0 commit comments