Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion crates/vm/src/types/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,14 +835,36 @@ pub trait Initializer: PyPayload {
#[pyslot]
#[inline]
fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
let zelf = zelf.try_into_value(vm)?;
#[cfg(debug_assertions)]
let class_name_for_debug = zelf.class().name().to_string();

let zelf = match zelf.try_into_value(vm) {
Ok(zelf) => zelf,
Err(err) => {
#[cfg(debug_assertions)]
{
if let Ok(msg) = err.as_object().repr(vm) {
let double_appearance =
msg.as_str().matches(&class_name_for_debug as &str).count() == 2;
if double_appearance {
panic!(
"This type `{}` doesn't seem to support `init`. Override `slot_init` instead: {}",
class_name_for_debug, msg
);
}
}
}
return Err(err);
}
};
let args: Self::Args = args.bind(vm)?;
Self::init(zelf, args, vm)
}

#[pymethod]
#[inline]
fn __init__(zelf: PyRef<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> {
// TODO: check if this is safe. zelf may need to be `PyObjectRef`
Self::init(zelf, args, vm)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/vm/vm_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ impl VirtualMachine {
#[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 += " It might mean this type doesn't support subclassing very well. e.g. Did you forget to add `#[pyclass(with(Constructor))]`?";
msg
} else {
msg
Expand Down
Loading