astral-sh/ruff · warning
Expected at least one argument in outer function call
Error message
Expected at least one argument in outer function call
What it means
Raised by the C418/unnecessary-double-cast-or-process fix (e.g. `list(tuple(x))`, `set(list(x))`) when the outer call has no arguments at all. The fixer needs at least the inner argument to rebuild the simplified call; with zero arguments it bails.
Source
Thrown at crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs:568
outer_call.args = match outer_call.args.split_first() {
Some((first, rest)) => {
let inner_call = match_call(&first.value)?;
if let Some(arg) = inner_call
.args
.iter()
.find(|argument| argument.keyword.is_none())
{
let mut arg = arg.clone();
arg.comma.clone_from(&first.comma);
arg.whitespace_after_arg = first.whitespace_after_arg.clone();
iter::once(arg)
.chain(rest.iter().cloned())
.collect::<Vec<_>>()
} else {
rest.to_vec()
}
}
None => bail!("Expected at least one argument in outer function call"),
};
Ok(Edit::range_replacement(
tree.codegen_stylist(stylist),
expr.range(),
))
}
/// (C416) Convert `[i for i in x]` to `list(x)`.
pub(crate) fn fix_unnecessary_comprehension(
expr: &Expr,
locator: &Locator,
stylist: &Stylist,
) -> Result<Edit> {
let module_text = locator.slice(expr);
let mut tree = match_expression(module_text)?;
match &tree {View on GitHub (pinned to 26f38c119c)
Solutions
- Re-run ruff so the fix operates on fresh diagnostics.
- Rewrite manually: `list()` has no double-cast to remove; keep it as-is.
- Suppress the fix and keep only the diagnostic if the call is intentionally empty.
Example fix
// before list(tuple(items)) // after list(items)
Defensive patterns
Strategy: validation
Validate before calling
assert bool(cast_call.args), 'C418 fix needs at least one argument'
Type guard
def has_args(expr):
return isinstance(expr, ast.Call) and len(expr.args) >= 1 Try / catch
try:
apply_autofix(diagnostic)
except Exception:
keep_code_as_is() Prevention
- Don't feed empty calls like list()/set() to the double-cast fix
- Refresh diagnostics before fixing
- Rewrite nested casts manually when shapes are unusual
When it happens
Trigger: `ruff check --fix` on a call like `list()` matched against the double-cast rule, or a stale diagnostic whose ranges no longer line up with the edited source.
Common situations: Applying cached/stale diagnostics to changed code; unusual constructs like `list(*args)` that parsed into an argument shape the fixer did not expect.
Related errors
- Expected Expression::Tuple | Expression::List
- Expected each argument to be a tuple of length two
- Expected one argument in outer function call
- Expected Expression::ListComp | Expression:SetComp | Express
- Expected two arguments
AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05).
Data as JSON: /api/errors/b5929ff20a27fe4a.
Report an issue: GitHub.