Skip to content

Commit cf1c098

Browse files
GH-100101: Clarify documentation of zip's strict option (GH-100103)
1 parent c4c5790 commit cf1c098

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Doc/library/functions.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,14 +1923,24 @@ are always available. They are listed here in alphabetical order.
19231923
>>> list(zip(('a', 'b', 'c'), (1, 2, 3), strict=True))
19241924
[('a', 1), ('b', 2), ('c', 3)]
19251925

1926-
Unlike the default behavior, it checks that the lengths of iterables are
1927-
identical, raising a :exc:`ValueError` if they aren't:
1928-
1929-
>>> list(zip(range(3), ['fee', 'fi', 'fo', 'fum'], strict=True))
1926+
Unlike the default behavior, it raises a :exc:`ValueError` if one iterable
1927+
is exhausted before the others:
1928+
1929+
>>> for item in zip(range(3), ['fee', 'fi', 'fo', 'fum'], strict=True): # doctest: +SKIP
1930+
... print(item)
1931+
...
1932+
(0, 'fee')
1933+
(1, 'fi')
1934+
(2, 'fo')
19301935
Traceback (most recent call last):
19311936
...
19321937
ValueError: zip() argument 2 is longer than argument 1
19331938

1939+
..
1940+
This doctest is disabled because doctest does not support capturing
1941+
output and exceptions in the same code unit.
1942+
https://github.com/python/cpython/issues/65382
1943+
19341944
Without the ``strict=True`` argument, any bug that results in iterables of
19351945
different lengths will be silenced, possibly manifesting as a hard-to-find
19361946
bug in another part of the program.

0 commit comments

Comments
 (0)