Skip to content

Commit f0df2ca

Browse files
committed
Skip unnecessary optional-field validation walks
When a known binding receives no positional arguments and requires no parameters, there can be no missing or duplicate parameters. Validate the supplied keyword names directly without walking optional fields. Assisted-by: OpenAI Codex:model version not exposed
1 parent a950ed9 commit f0df2ca

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

‎crates/vm/src/function/argument.rs‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -728,17 +728,21 @@ impl BindingShape {
728728
)));
729729
}
730730

731-
let mut matched = BindingMatch {
732-
positional: 0,
733-
position: 0,
734-
skip: instance,
735-
duplicate: None,
736-
};
737-
if let Err(missing) = matched.walk(params, nargs, &args.kwargs) {
738-
return Some(missing.into_exception(arity, nargs, 0, callee, vm));
739-
}
740-
if let Some((name, pos)) = matched.duplicate {
741-
return Some(callee.given_by_name_and_position(name, pos, vm));
731+
// Without positional or required arguments, only keyword names need
732+
// checking. Avoid walking optional fields on calls such as list.sort.
733+
if nargs != 0 || self.required_positional != 0 || self.required_keyword_only {
734+
let mut matched = BindingMatch {
735+
positional: 0,
736+
position: 0,
737+
skip: instance,
738+
duplicate: None,
739+
};
740+
if let Err(missing) = matched.walk(params, nargs, &args.kwargs) {
741+
return Some(missing.into_exception(arity, nargs, 0, callee, vm));
742+
}
743+
if let Some((name, pos)) = matched.duplicate {
744+
return Some(callee.given_by_name_and_position(name, pos, vm));
745+
}
742746
}
743747
if !self.var_keyword {
744748
for name in args.kwargs.keys() {

0 commit comments

Comments
 (0)