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

Method try_from_object

crates/vm/src/exceptions.rs:420–436  ·  view source on GitHub ↗
(vm: &VirtualMachine, obj: PyObjectRef)

Source from the content-addressed store, hash-verified

418
419impl TryFromObject for ExceptionCtor {
420 fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
421 obj.downcast::<PyType>()
422 .and_then(|cls| {
423 if cls.fast_issubclass(vm.ctx.exceptions.base_exception_type) {
424 Ok(Self::Class(cls))
425 } else {
426 Err(cls.into())
427 }
428 })
429 .or_else(|obj| obj.downcast::<PyBaseException>().map(Self::Instance))
430 .map_err(|obj| {
431 vm.new_type_error(format!(
432 "exceptions must be classes or instances deriving from BaseException, not {}",
433 obj.class().name()
434 ))
435 })
436 }
437}
438
439impl ExceptionCtor {

Callers

nothing calls this directly

Calls 4

fast_issubclassMethod · 0.80
ClassClass · 0.50
ErrClass · 0.50
mapMethod · 0.45

Tested by

no test coverage detected