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

Method new_downcast_error

crates/vm/src/vm/vm_new.rs:722–742  ·  view source on GitHub ↗
(
        &self,
        msg: &'static str,
        error_type: &'static Py<PyType>,
        class: &Py<PyType>,
        obj: &PyObject, // the impl Borrow allows to pass PyObjectRef or &PyObject
    

Source from the content-addressed store, hash-verified

720 }
721
722 fn new_downcast_error(
723 &self,
724 msg: &'static str,
725 error_type: &'static Py<PyType>,
726 class: &Py<PyType>,
727 obj: &PyObject, // the impl Borrow allows to pass PyObjectRef or &PyObject
728 ) -> PyBaseExceptionRef {
729 let actual_class = obj.class();
730 let actual_type = &*actual_class.name();
731 let expected_type = &*class.name();
732 let msg = format!("Expected {msg} '{expected_type}' but '{actual_type}' found.");
733 #[cfg(debug_assertions)]
734 let msg = if class.get_id() == actual_class.get_id() {
735 let mut msg = msg;
736 msg += " It might mean this type doesn't support subclassing very well. e.g. Did you forget to add `#[pyclass(with(Constructor))]`?";
737 msg
738 } else {
739 msg
740 };
741 self.new_exception_msg(error_type.to_owned(), msg.into())
742 }
743
744 pub(crate) fn new_downcast_runtime_error(
745 &self,

Callers 2

Calls 5

new_exception_msgMethod · 0.80
classMethod · 0.45
nameMethod · 0.45
get_idMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected