Skip to content

Commit 6a5d3ff

Browse files
bpo-40636: Clarify the zip built-in docstring. (GH-20118)
Clarify the zip built-in docstring. This puts much simpler text up front along with an example. As it was, the zip built-in docstring was technically correct. But too technical for the reader who shouldn't _need_ to know about `__next__` and `StopIteration` as most people do not need to understand the internal implementation details of the iterator protocol in their daily life. This is a documentation only change, intended to be backported to 3.8; it is only tangentially related to PEP-618 which might offer new behavior options in the future. Wording based a bit more on enumerate per Brandt's suggestion. This gets rid of the legacy wording paragraph which seems too tied to implementation details of the iterator protocol which isn't relevant here. Co-authored-by: Brandt Bucher <[email protected]>
1 parent 938717f commit 6a5d3ff

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Lib/test/test_doctest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def non_Python_modules(): r"""
669669
True
670670
>>> real_tests = [t for t in tests if len(t.examples) > 0]
671671
>>> len(real_tests) # objects that actually have doctests
672-
12
672+
13
673673
>>> for t in real_tests:
674674
... print('{} {}'.format(len(t.examples), t.name))
675675
...
@@ -685,6 +685,7 @@ def non_Python_modules(): r"""
685685
2 builtins.int.bit_length
686686
5 builtins.memoryview.hex
687687
1 builtins.oct
688+
1 builtins.zip
688689
689690
Note here that 'bin', 'oct', and 'hex' are functions; 'float.as_integer_ratio',
690691
'float.hex', and 'int.bit_length' are methods; 'float.fromhex' is a classmethod,

Python/bltinmodule.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,12 +2649,15 @@ static PyMethodDef zip_methods[] = {
26492649
};
26502650

26512651
PyDoc_STRVAR(zip_doc,
2652-
"zip(*iterables) --> zip object\n\
2652+
"zip(*iterables) --> A zip object yielding tuples until an input is exhausted.\n\
26532653
\n\
2654-
Return a zip object whose .__next__() method returns a tuple where\n\
2655-
the i-th element comes from the i-th iterable argument. The .__next__()\n\
2656-
method continues until the shortest iterable in the argument sequence\n\
2657-
is exhausted and then it raises StopIteration.");
2654+
>>> list(zip('abcdefg', range(3), range(4)))\n\
2655+
[('a', 0, 0), ('b', 1, 1), ('c', 2, 2)]\n\
2656+
\n\
2657+
The zip object yields n-length tuples, where n is the number of iterables\n\
2658+
passed as positional arguments to zip(). The i-th element in every tuple\n\
2659+
comes from the i-th iterable argument to zip(). This continues until the\n\
2660+
shortest argument is exhausted.");
26582661

26592662
PyTypeObject PyZip_Type = {
26602663
PyVarObject_HEAD_INIT(&PyType_Type, 0)

0 commit comments

Comments
 (0)