diff --git a/crates/ruff_linter/resources/test/fixtures/pylint/nested_min_max.py b/crates/ruff_linter/resources/test/fixtures/pylint/nested_min_max.py index d35f1a50b6..830025bc83 100644 --- a/crates/ruff_linter/resources/test/fixtures/pylint/nested_min_max.py +++ b/crates/ruff_linter/resources/test/fixtures/pylint/nested_min_max.py @@ -55,3 +55,8 @@ max_word_len = max( *(len(word) for word in "blah blah blah".split(" ")), len("Done!"), ) + + +# Outer call has a single argument, inner call has multiple arguments; should not trigger. +min(min([2, 3], [4, 1])) +max(max([2, 4], [3, 1])) diff --git a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs index 9383906df9..6756e9e0a0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs @@ -155,9 +155,11 @@ pub(crate) fn nested_min_max( let Some(min_max) = MinMax::try_from_call(func, keywords, checker.semantic()) else { return; }; - - if matches!(&args, [Expr::Call(ast::ExprCall { arguments: Arguments {args, .. }, .. })] if args.len() == 1) - { + // It's only safe to flatten nested calls if the outer call has more than one argument. + // When the outer call has a single argument, flattening would change the semantics by + // changing the shape of the call from treating the inner result as an iterable (or a scalar) + // to passing multiple arguments directly, which can lead to behavioral changes. + if args.len() < 2 { return; }