Skip to content

Commit ac31120

Browse files
GH-100101: Clarify documentation of zip's strict option (GH-100103)
(cherry picked from commit cf1c098) Co-authored-by: JustAnotherArchivist <[email protected]>
1 parent 9120450 commit ac31120

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
@@ -1918,14 +1918,24 @@ are always available. They are listed here in alphabetical order.
19181918
>>> list(zip(('a', 'b', 'c'), (1, 2, 3), strict=True))
19191919
[('a', 1), ('b', 2), ('c', 3)]
19201920

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

1934+
..
1935+
This doctest is disabled because doctest does not support capturing
1936+
output and exceptions in the same code unit.
1937+
https://github.com/python/cpython/issues/65382
1938+
19291939
Without the ``strict=True`` argument, any bug that results in iterables of
19301940
different lengths will be silenced, possibly manifesting as a hard-to-find
19311941
bug in another part of the program.

0 commit comments

Comments
 (0)