Skip to content

Commit db283a6

Browse files
authored
Merge pull request #5477 from youknowone/better-downcast-error
Add better panic for abnormal downcast error
2 parents c642aef + 5ad7e97 commit db283a6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

vm/src/vm/vm_new.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,15 @@ impl VirtualMachine {
365365
let actual_class = obj.class();
366366
let actual_type = &*actual_class.name();
367367
let expected_type = &*class.name();
368-
let msg = format!("Expected {msg} '{expected_type}' but '{actual_type}' found");
368+
let msg = format!("Expected {msg} '{expected_type}' but '{actual_type}' found.");
369+
#[cfg(debug_assertions)]
370+
let msg = if class.get_id() == actual_class.get_id() {
371+
let mut msg = msg;
372+
msg += " Did you forget to add `#[pyclass(with(Constructor))]`?";
373+
msg
374+
} else {
375+
msg
376+
};
369377
self.new_exception_msg(error_type.to_owned(), msg)
370378
}
371379

0 commit comments

Comments
 (0)