{"record":{"id":"5fa117c954ae62ba","repo":"astral-sh/ruff","slug":"expected-one-argument-in-outer-function-call","errorCode":null,"errorMessage":"Expected one argument in outer function call","messagePattern":"Expected one argument in outer function call","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs","lineNumber":429,"sourceCode":"        expr.range(),\n    ))\n}\n\n/// (C413) Convert `list(sorted([2, 3, 1]))` to `sorted([2, 3, 1])`.\n/// (C413) Convert `reversed(sorted([2, 3, 1]))` to `sorted([2, 3, 1],\n/// reverse=True)`.\npub(crate) fn fix_unnecessary_call_around_sorted(\n    expr: &Expr,\n    locator: &Locator,\n    stylist: &Stylist,\n) -> Result<Edit> {\n    let module_text = locator.slice(expr);\n    let mut tree = match_expression(module_text)?;\n    let outer_call = match_call_mut(&mut tree)?;\n    let inner_call = match &outer_call.args[..] {\n        [arg] => match_call(&arg.value)?,\n        _ => {\n            bail!(\"Expected one argument in outer function call\");\n        }\n    };\n\n    let inner_needs_parens = matches!(\n        inner_call.whitespace_after_func,\n        ParenthesizableWhitespace::ParenthesizedWhitespace(_)\n    );\n\n    if let Expression::Name(outer_name) = &*outer_call.func {\n        if outer_name.value == \"list\" {\n            tree = Expression::Call(Box::new((*inner_call).clone()));\n            if inner_needs_parens {\n                tree = tree.with_parens(LeftParen::default(), RightParen::default());\n            }\n        } else {\n            // If the `reverse` argument is used...\n            let args = if inner_call.args.iter().any(|arg| {\n                matches!(","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs#L411-L447","documentation":"Raised by the C411/unnecessary-call-around-sorted fix (e.g. `sorted(list(...))` -> `sorted(...)`) when the outer call to `sorted` does not have exactly one argument. The fixer rewrites only single-argument forms; anything else cannot be transformed safely.","triggerScenarios":"`ruff check --fix` on `sorted(a, b)` or `sorted()` — the outer `sorted(...)` call has zero or multiple arguments instead of one.","commonSituations":"Code where extra arguments (`key=`, `reverse=`) were added after the diagnostic was computed; stale diagnostics applied to edited code; hand-edited autofix inputs.","solutions":["Re-run `ruff check --fix` so diagnostics match current code (stale ranges often cause shape mismatches).","Rewrite manually: keep `sorted(x, key=..., reverse=...)` as-is; the rule only simplifies `sorted(list(x))` forms.","Disable the fix (use the diagnostic without `--fix`) if the call shape is intentionally complex."],"exampleFix":"// before\nsorted(list(items), reverse=True)\n// after\nsorted(items, reverse=True)","handlingStrategy":"validation","validationCode":"assert len(sorted_call.args) == 1, 'C411 fix needs exactly one argument in sorted(...)'","typeGuard":"def single_arg_call(expr):\n    return isinstance(expr, ast.Call) and len(expr.args) == 1","tryCatchPattern":"try:\n    apply_autofix(diagnostic)\nexcept Exception:\n    keep_code_as_is()","preventionTips":["Re-run ruff after editing sorted(...) arguments","Apply key=/reverse= only where the rule is suppressed","Avoid applying stale cached diagnostics"],"tags":["rust","ruff","lint-autofix","flake8-comprehensions"],"backgroundTag":"stale-diagnostic-ast-mismatch","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}