astral-sh/ruff · error
argument index should be valid
Error message
argument index should be valid
What it means
CallableBinding::type_for_argument reads the inferred argument types at `argument_index` from the CallArguments captured for the call; every binding is expected to cover every argument index recorded at the call site. The expect is an index-bounds panic routed through CallArguments::argument_types.
Source
Thrown at crates/ty_python_semantic/src/types/call/bind.rs:1405
env,
constraints,
call_arguments,
call_expression_tcx,
dataclass_field_specifiers,
);
}
// For intersection elements with at least one successful binding,
// filter out the failing bindings after deferred constructor checks.
for element in &mut self.elements {
element.retain_successful(db);
}
self.as_result(db)
}
/// Finalize the bindings after a provisional check, retaining only those that contribute
/// to the final call evaluation.
pub(crate) fn finalize_argument_inference(
&mut self,
db: &'db dyn Db,
env: &ProgramEnvironment<'db>,
call_arguments: &CallArguments<'_, 'db>,
dataclass_field_specifiers: &[Type<'db>],
) -> Result<(), CallErrorKind> {
self.evaluate_known_cases(db, env, call_arguments, dataclass_field_specifiers);
for constructor in self.iter_constructor_items_mut() {
if constructor.discard_downstream_constructor(db, env)
&& let Some(downstream) = constructor.downstream_constructor_mut()
{
let _ = downstream.finalize_argument_inference(
db,
env,
call_arguments,
dataclass_field_specifiers,View on GitHub (pinned to 15f3fe6b15)
Solutions
- Minimize the call (overloads plus default/star arguments) and file a ty issue with the backtrace
- As a contributor: check `argument_types(index)` for None and fall back to the default argument type instead of unwrapping
- Verify the binding was not cached from an earlier iteration with different arity
Example fix
// before
let argument_types = call_arguments.argument_types(argument_index).expect("argument index should be valid");
// after
let Some(argument_types) = call_arguments.argument_types(argument_index) else {
return default_type;
}; Defensive patterns
Strategy: validation
Validate before calling
if let Some(argument_types) = call_arguments.argument_types(argument_index) {
// proceed with the inferred type
} else {
// fall back to the default argument type
} Prevention
- Validate argument_index against the recorded arguments before reading inferred types
- Ensure parameter/argument counting rules match between matching and reporting for defaults and star-args
- Beware replaying bindings from a cached iteration after the call's arity changed
When it happens
Trigger: An argument_index beyond the number of recorded argument entries: a binding whose matching overloads reference a parameter position past the provided arguments (defaults or *args miscounting), or a binding replayed against a different call's arguments.
Common situations: Calls combining defaults, star-args, and overloaded signatures; stale bindings after an edit changes call arity during incremental checking.
Related errors
- argument index should be valid
- bindings must not be empty
- checked bindings are stable across fixpoint iterations
- ParamSpec sub-call should only contain a single CallableBind
- argument index should not be out of range
AI-assisted analysis of astral-sh/ruff@15f3fe6b15 (2026-08-20).
Data as JSON: /api/errors/f07b30255b72e851.
Report an issue: GitHub.