MCPcopy Index your code
hub / github.com/RustPython/RustPython / bind

Method bind

crates/vm/src/function/argument.rs:276–292  ·  view source on GitHub ↗

Binds these arguments to their respective values. If there is an insufficient number of arguments, there are leftover arguments after performing the binding, or if an argument is not of the expected type, a TypeError is raised. If the given `FromArgs` includes any conversions, exceptions raised during the conversion will halt the binding and return the error.

(mut self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

274 /// If the given `FromArgs` includes any conversions, exceptions raised
275 /// during the conversion will halt the binding and return the error.
276 pub fn bind<T: FromArgs>(mut self, vm: &VirtualMachine) -> PyResult<T> {
277 let given_args = self.args.len();
278 let bound = T::from_args(vm, &mut self)
279 .map_err(|e| e.into_exception(T::arity(), given_args, vm))?;
280
281 if !self.args.is_empty() {
282 Err(vm.new_type_error(format!(
283 "expected at most {} arguments, got {}",
284 T::arity().end(),
285 given_args,
286 )))
287 } else if let Some(err) = self.check_kwargs_empty(vm) {
288 Err(err)
289 } else {
290 Ok(bound)
291 }
292 }
293
294 pub fn check_kwargs_empty(&self, vm: &VirtualMachine) -> Option<PyBaseExceptionRef> {
295 self.kwargs

Callers 15

slot_initMethod · 0.45
slot_newMethod · 0.45
slot_newMethod · 0.45
slot_initMethod · 0.45
slot_callMethod · 0.45
slot_newMethod · 0.45
slot_initMethod · 0.45
slot_initMethod · 0.45
slot_newMethod · 0.45
comerror_initFunction · 0.45
slot_newMethod · 0.45
callMethod · 0.45

Calls 5

into_exceptionMethod · 0.80
check_kwargs_emptyMethod · 0.80
ErrClass · 0.50
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected