summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na92@gmail.com>2020-01-11 01:31:43 +0900
committerVictor Stinner <vstinner@python.org>2020-01-10 17:31:43 +0100
commitabdc634f337ce4943cd7d13587936837aac2ecc9 (patch)
tree1cd9642117077a38a913992b7c287002f7a22485
parentc39b52f1527868c7ada9385669c38edf98858921 (diff)
downloadcpython-git-abdc634f337ce4943cd7d13587936837aac2ecc9.tar.gz
bpo-39200: Correct the error message for min/max builtin function (GH-17814)
Correct the error message when calling the min() or max() with no arguments.
-rw-r--r--Lib/test/test_builtin.py14
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2020-01-04-01-14-32.bpo-39200.8Z9DYp.rst2
-rw-r--r--Python/bltinmodule.c9
3 files changed, 21 insertions, 4 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 6a88454289..5c553a92b9 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -949,7 +949,12 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(max(1, 2.0, 3), 3)
self.assertEqual(max(1.0, 2, 3), 3)
- self.assertRaises(TypeError, max)
+ with self.assertRaisesRegex(
+ TypeError,
+ 'max expected at least 1 argument, got 0'
+ ):
+ max()
+
self.assertRaises(TypeError, max, 42)
self.assertRaises(ValueError, max, ())
class BadSeq:
@@ -1003,7 +1008,12 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(min(1, 2.0, 3), 1)
self.assertEqual(min(1.0, 2, 3), 1.0)
- self.assertRaises(TypeError, min)
+ with self.assertRaisesRegex(
+ TypeError,
+ 'min expected at least 1 argument, got 0'
+ ):
+ min()
+
self.assertRaises(TypeError, min, 42)
self.assertRaises(ValueError, min, ())
class BadSeq:
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-01-04-01-14-32.bpo-39200.8Z9DYp.rst b/Misc/NEWS.d/next/Core and Builtins/2020-01-04-01-14-32.bpo-39200.8Z9DYp.rst
new file mode 100644
index 0000000000..71e4072099
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-01-04-01-14-32.bpo-39200.8Z9DYp.rst
@@ -0,0 +1,2 @@
+Correct the error message when calling the :func:`min` or :func:`max` with
+no arguments. Patch by Dong-hee Na.
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 34267685be..4f833c1f46 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1589,10 +1589,15 @@ min_max(PyObject *args, PyObject *kwds, int op)
const int positional = PyTuple_Size(args) > 1;
int ret;
- if (positional)
+ if (positional) {
v = args;
- else if (!PyArg_UnpackTuple(args, name, 1, 1, &v))
+ }
+ else if (!PyArg_UnpackTuple(args, name, 1, 1, &v)) {
+ if (PyExceptionClass_Check(PyExc_TypeError)) {
+ PyErr_Format(PyExc_TypeError, "%s expected at least 1 argument, got 0", name);
+ }
return NULL;
+ }
emptytuple = PyTuple_New(0);
if (emptytuple == NULL)