Add better panic for abnormal downcast error

This commit is contained in:
Jeong YunWon
2025-01-16 00:52:16 +09:00
parent b7a7b6b923
commit 5ad7e97e05

View File

@@ -365,7 +365,15 @@ impl VirtualMachine {
let actual_class = obj.class();
let actual_type = &*actual_class.name();
let expected_type = &*class.name();
let msg = format!("Expected {msg} '{expected_type}' but '{actual_type}' found");
let msg = format!("Expected {msg} '{expected_type}' but '{actual_type}' found.");
#[cfg(debug_assertions)]
let msg = if class.get_id() == actual_class.get_id() {
let mut msg = msg;
msg += " Did you forget to add `#[pyclass(with(Constructor))]`?";
msg
} else {
msg
};
self.new_exception_msg(error_type.to_owned(), msg)
}