Skip to content

Commit 2940ef8

Browse files
authored
Merge pull request RustPython#4236 from devonhollowood/minmax
Fix compatibility bug for min/max builtins
2 parents 4331d65 + 052b87b commit 2940ef8

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

Lib/test/test_builtin.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,6 @@ def test_map_pickle(self):
10271027
m2 = map(map_char, "Is this the real life?")
10281028
self.check_iter_pickle(m1, list(m2), proto)
10291029

1030-
# TODO: RUSTPYTHON
1031-
@unittest.expectedFailure
10321030
def test_max(self):
10331031
self.assertEqual(max('123123'), '3')
10341032
self.assertEqual(max(1, 2, 3), 3)
@@ -1088,8 +1086,6 @@ def __getitem__(self, index):
10881086
self.assertEqual(max(data, key=f),
10891087
sorted(reversed(data), key=f)[-1])
10901088

1091-
# TODO: RUSTPYTHON
1092-
@unittest.expectedFailure
10931089
def test_min(self):
10941090
self.assertEqual(min('123123'), '1')
10951091
self.assertEqual(min(1, 2, 3), 1)

vm/src/stdlib/builtins.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ mod builtins {
478478
std::cmp::Ordering::Greater => {
479479
if default.is_some() {
480480
return Err(vm.new_type_error(format!(
481-
"Cannot specify a default for {} with multiple positional arguments",
481+
"Cannot specify a default for {}() with multiple positional arguments",
482482
func_name
483483
)));
484484
}
@@ -487,7 +487,9 @@ mod builtins {
487487
std::cmp::Ordering::Equal => args.args[0].try_to_value(vm)?,
488488
std::cmp::Ordering::Less => {
489489
// zero arguments means type error:
490-
return Err(vm.new_type_error("Expected 1 or more arguments".to_owned()));
490+
return Err(
491+
vm.new_type_error(format!("{} expected at least 1 argument, got 0", func_name))
492+
);
491493
}
492494
};
493495

@@ -496,7 +498,7 @@ mod builtins {
496498
Some(x) => x,
497499
None => {
498500
return default.ok_or_else(|| {
499-
vm.new_value_error(format!("{} arg is an empty sequence", func_name))
501+
vm.new_value_error(format!("{}() arg is an empty sequence", func_name))
500502
})
501503
}
502504
};
@@ -524,12 +526,12 @@ mod builtins {
524526

525527
#[pyfunction]
526528
fn max(args: FuncArgs, vm: &VirtualMachine) -> PyResult {
527-
min_or_max(args, vm, "max()", PyComparisonOp::Gt)
529+
min_or_max(args, vm, "max", PyComparisonOp::Gt)
528530
}
529531

530532
#[pyfunction]
531533
fn min(args: FuncArgs, vm: &VirtualMachine) -> PyResult {
532-
min_or_max(args, vm, "min()", PyComparisonOp::Lt)
534+
min_or_max(args, vm, "min", PyComparisonOp::Lt)
533535
}
534536

535537
#[pyfunction]

0 commit comments

Comments
 (0)