(
&self,
msg: &'static str,
error_type: &'static Py<PyType>,
class: &Py<PyType>,
obj: &PyObject, // the impl Borrow allows to pass PyObjectRef or &PyObject
| 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, |
no test coverage detected