From 6802cfcca9cdcfd9a75b173f9b1b1392fd962c01 Mon Sep 17 00:00:00 2001 From: Nnarol Date: Mon, 7 Feb 2022 00:39:07 +0100 Subject: [PATCH 1/5] Fix empty iter error message in min/max Change misleading "empty sequence" to "empty iterable" in builtins.min/max. Update corresponding test to be more specific and match the error string. --- Lib/test/test_builtin.py | 12 ++++++++++-- Python/bltinmodule.c | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index c6e67cc2910cf0..941bee53cb94b4 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1031,7 +1031,11 @@ def test_max(self): max() self.assertRaises(TypeError, max, 42) - self.assertRaises(ValueError, max, ()) + with self.assertRaisesRegex( + ValueError, + r'max\(\) iterable argument is empty' + ): + max(()) class BadSeq: def __getitem__(self, index): raise ValueError @@ -1090,7 +1094,11 @@ def test_min(self): min() self.assertRaises(TypeError, min, 42) - self.assertRaises(ValueError, min, ()) + with self.assertRaisesRegex( + ValueError, + r'min\(\) iterable argument is empty' + ): + min(()) class BadSeq: def __getitem__(self, index): raise ValueError diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index ed612091d83941..c96fca9c3e0569 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1786,7 +1786,7 @@ min_max(PyObject *args, PyObject *kwds, int op) maxitem = defaultval; } else { PyErr_Format(PyExc_ValueError, - "%s() arg is an empty sequence", name); + "%s() iterable argument is empty", name); } } else From 2f9b0eab41ee726a85819cfdc7ca74fc92e67578 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 7 Feb 2022 17:40:24 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst new file mode 100644 index 00000000000000..be791ce0daf40f --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst @@ -0,0 +1 @@ +Change exception message of :func:`min()` and :func:`max()` to refer to an iterable rather than a sequence if an empty iterable of values to select from was provided.. \ No newline at end of file From 4b9ab205130a352f94429a5eb0b33c13fcf46d62 Mon Sep 17 00:00:00 2001 From: Nnarol Date: Tue, 8 Feb 2022 22:17:54 +0100 Subject: [PATCH 3/5] Update Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst Spelling fix in RST documentation. Co-authored-by: Nikita Sobolev --- .../Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst index be791ce0daf40f..7b6ea6ced039a9 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst @@ -1 +1 @@ -Change exception message of :func:`min()` and :func:`max()` to refer to an iterable rather than a sequence if an empty iterable of values to select from was provided.. \ No newline at end of file +Change exception message of :func:`min()` and :func:`max()` to refer to an iterable rather than a sequence if an empty iterable of values to select from was provided. \ No newline at end of file From f8dcf8ad7a0f722adf0fe57460392edbdb79b787 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 3 May 2022 09:12:02 -0600 Subject: [PATCH 4/5] newline in NEWS file --- .../Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst index 7b6ea6ced039a9..d157e0b22a4e39 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst @@ -1 +1,2 @@ -Change exception message of :func:`min()` and :func:`max()` to refer to an iterable rather than a sequence if an empty iterable of values to select from was provided. \ No newline at end of file +Change exception message of :func:`min()` and :func:`max()` to refer to an iterable +rather than a sequence if an empty iterable of values to select from was provided. From 74ea60f06c44f36f153d591692764f2e8f4f76bc Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 4 May 2022 23:08:19 -0500 Subject: [PATCH 5/5] Delete 2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst No news entries are needed for minor docs fixes. --- .../Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst deleted file mode 100644 index d157e0b22a4e39..00000000000000 --- a/Misc/NEWS.d/next/Core and Builtins/2022-02-07-17-40-23.bpo-46671.CmpNlQ.rst +++ /dev/null @@ -1,2 +0,0 @@ -Change exception message of :func:`min()` and :func:`max()` to refer to an iterable -rather than a sequence if an empty iterable of values to select from was provided.