Merge pull request #5477 from youknowone/better-downcast-error

Add better panic for abnormal downcast error
This commit is contained in:
Jeong, YunWon authored and GitHub committed 2025-01-21 13:54:45 +09:00
commit db283a66e8
1 file changed
+9 -1
+9 -1
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)
}