8000 GH-100101: Clarify documentation of zip's strict option (GH-100103) · python/cpython@4217faf · GitHub
[go: up one dir, main page]

Skip to content

Commit 4217faf

Browse files
GH-100101: Clarify documentation of zip's strict option (GH-100103)
(cherry picked from commit cf1c098) Co-authored-by: JustAnotherArchivist <JustAnotherArchivist@users.noreply.github.com>
1 parent 97a3e18 commit 4217faf

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

1897-
Unlike the default behavior, it checks that the lengths of iterables are
1898-
identical, raising a :exc:`ValueError` if they aren't:
1899-
1900-
>>> list(zip(range(3), ['fee', 'fi', 'fo', 'fum'], strict=True))
1897+
Unlike the default behavior, it raises a :exc:`ValueError` if one iterable
1898+
is exhausted before the others:
1899+
1900+
>>> for item in zip(range(3), ['fee', 'fi', 'fo', 'fum'], strict=True): # doctest: +SKIP
1901+
... print(item)
1902+
...
1903+
(0, 'fee')
1904+
(1, 'fi')
1905+
(2, 'fo')
19011906
Traceback (most recent call last):
19021907
...
19031908
ValueError: zip() argument 2 is longer than argument 1
19041909

1910+
..
1911+
This doctest is disabled because doctest does not support capturing
1912+
output and exceptions in the same code unit.
1913+
https://github.com/python/cpython/issues/65382
1914+
19051915
Without the ``strict=True`` argument, any bug that results in iterables of
19061916
different lengths will be silenced, possibly manifesting as a hard-to-find
19071917
bug in another part of the program.

0 commit comments

Comments
 (0)
0