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

Method instantiate_value

crates/vm/src/exceptions.rs:447–473  ·  view source on GitHub ↗
(
        self,
        value: PyObjectRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

445 }
446
447 pub fn instantiate_value(
448 self,
449 value: PyObjectRef,
450 vm: &VirtualMachine,
451 ) -> PyResult<PyBaseExceptionRef> {
452 let exc_inst = value.clone().downcast::<PyBaseException>().ok();
453 match (self, exc_inst) {
454 // both are instances; which would we choose?
455 (Self::Instance(_exc_a), Some(_exc_b)) => {
456 Err(vm.new_type_error("instance exception may not have a separate value"))
457 }
458 // if the "type" is an instance and the value isn't, use the "type"
459 (Self::Instance(exc), None) => Ok(exc),
460 // if the value is an instance of the type, use the instance value
461 (Self::Class(cls), Some(exc)) if exc.fast_isinstance(&cls) => Ok(exc),
462 // otherwise; construct an exception of the type using the value as args
463 (Self::Class(cls), _) => {
464 let args = match_class!(match value {
465 PyNone => vec![],
466 tup @ PyTuple => tup.to_vec(),
467 exc @ PyBaseException => exc.args().to_vec(),
468 obj => vec![obj],
469 });
470 vm.invoke_exception(cls, args)
471 }
472 }
473 }
474}
475
476#[derive(Debug)]

Callers 2

normalize_exceptionMethod · 0.80
gen_throwMethod · 0.80

Calls 5

okMethod · 0.80
fast_isinstanceMethod · 0.80
invoke_exceptionMethod · 0.80
ErrClass · 0.50
cloneMethod · 0.45

Tested by

no test coverage detected