Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c39b52f commit abdc634Copy full SHA for abdc634
3 files changed
Lib/test/test_builtin.py
@@ -949,7 +949,12 @@ def test_max(self):
949
self.assertEqual(max(1, 2.0, 3), 3)
950
self.assertEqual(max(1.0, 2, 3), 3)
951
952
- self.assertRaises(TypeError, max)
+ with self.assertRaisesRegex(
953
+ TypeError,
954
+ 'max expected at least 1 argument, got 0'
955
+ ):
956
+ max()
957
+
958
self.assertRaises(TypeError, max, 42)
959
self.assertRaises(ValueError, max, ())
960
class BadSeq:
@@ -1003,7 +1008,12 @@ def test_min(self):
1003
1008
self.assertEqual(min(1, 2.0, 3), 1)
1004
1009
self.assertEqual(min(1.0, 2, 3), 1.0)
1005
1010
1006
- self.assertRaises(TypeError, min)
1011
1012
1013
+ 'min expected at least 1 argument, got 0'
1014
1015
+ min()
1016
1007
1017
self.assertRaises(TypeError, min, 42)
1018
self.assertRaises(ValueError, min, ())
1019
Misc/NEWS.d/next/Core and Builtins/2020-01-04-01-14-32.bpo-39200.8Z9DYp.rst
@@ -0,0 +1,2 @@
1
+Correct the error message when calling the :func:`min` or :func:`max` with
2
+no arguments. Patch by Dong-hee Na.
Python/bltinmodule.c
@@ -1589,10 +1589,15 @@ min_max(PyObject *args, PyObject *kwds, int op)
1589
const int positional = PyTuple_Size(args) > 1;
1590
int ret;
1591
1592
- if (positional)
+ if (positional) {
1593
v = args;
1594
- else if (!PyArg_UnpackTuple(args, name, 1, 1, &v))
+ }
1595
+ else if (!PyArg_UnpackTuple(args, name, 1, 1, &v)) {
1596
+ if (PyExceptionClass_Check(PyExc_TypeError)) {
1597
+ PyErr_Format(PyExc_TypeError, "%s expected at least 1 argument, got 0", name);
1598
1599
return NULL;
1600
1601
1602
emptytuple = PyTuple_New(0);
1603
if (emptytuple == NULL)
0 commit comments