Skip to content

Commit 6802cfc

Browse files
author
Nnarol
committed
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.
1 parent c4e4b91 commit 6802cfc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Lib/test/test_builtin.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,11 @@ def test_max(self):
10311031
max()
10321032

10331033
self.assertRaises(TypeError, max, 42)
1034-
self.assertRaises(ValueError, max, ())
1034+
with self.assertRaisesRegex(
1035+
ValueError,
1036+
r'max\(\) iterable argument is empty'
1037+
):
1038+
max(())
10351039
class BadSeq:
10361040
def __getitem__(self, index):
10371041
raise ValueError
@@ -1090,7 +1094,11 @@ def test_min(self):
10901094
min()
10911095

10921096
self.assertRaises(TypeError, min, 42)
1093-
self.assertRaises(ValueError, min, ())
1097+
with self.assertRaisesRegex(
1098+
ValueError,
1099+
r'min\(\) iterable argument is empty'
1100+
):
1101+
min(())
10941102
class BadSeq:
10951103
def __getitem__(self, index):
10961104
raise ValueError

Python/bltinmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
17861786
maxitem = defaultval;
17871787
} else {
17881788
PyErr_Format(PyExc_ValueError,
1789-
"%s() arg is an empty sequence", name);
1789+
"%s() iterable argument is empty", name);
17901790
}
17911791
}
17921792
else

0 commit comments

Comments
 (0)