summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorNice Zombies <nineteendo19d0@gmail.com>2024-11-04 14:00:19 (GMT)
committerGitHub <noreply@github.com>2024-11-04 14:00:19 (GMT)
commit3032fcd90ecb745b737cbc93f694f9a802062a3a (patch)
tree24708afe3029ea00fd9ef72e0295593a90168f5d /Doc
parentbfc1d2504c183a9464e65c290e48516d176ea41f (diff)
downloadcpython-3032fcd90ecb745b737cbc93f694f9a802062a3a.zip
cpython-3032fcd90ecb745b737cbc93f694f9a802062a3a.tar.gz
cpython-3032fcd90ecb745b737cbc93f694f9a802062a3a.tar.bz2
gh-119793: Add optional length-checking to `map()` (GH-120471)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/functions.rst11
-rw-r--r--Doc/whatsnew/3.14.rst4
2 files changed, 12 insertions, 3 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 03fc41f..a7549b9 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -1205,14 +1205,19 @@ are always available. They are listed here in alphabetical order.
unchanged from previous versions.
-.. function:: map(function, iterable, *iterables)
+.. function:: map(function, iterable, /, *iterables, strict=False)
Return an iterator that applies *function* to every item of *iterable*,
yielding the results. If additional *iterables* arguments are passed,
*function* must take that many arguments and is applied to the items from all
iterables in parallel. With multiple iterables, the iterator stops when the
- shortest iterable is exhausted. For cases where the function inputs are
- already arranged into argument tuples, see :func:`itertools.starmap`\.
+ shortest iterable is exhausted. If *strict* is ``True`` and one of the
+ iterables is exhausted before the others, a :exc:`ValueError` is raised. For
+ cases where the function inputs are already arranged into argument tuples,
+ see :func:`itertools.starmap`.
+
+ .. versionchanged:: 3.14
+ Added the *strict* parameter.
.. function:: max(iterable, *, key=None)
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index deee683..80c1a93 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -175,6 +175,10 @@ Improved error messages
Other language changes
======================
+* The :func:`map` built-in now has an optional keyword-only *strict* flag
+ like :func:`zip` to check that all the iterables are of equal length.
+ (Contributed by Wannes Boeykens in :gh:`119793`.)
+
* Incorrect usage of :keyword:`await` and asynchronous comprehensions
is now detected even if the code is optimized away by the :option:`-O`
command-line option. For example, ``python -O -c 'assert await 1'``